修改IDEA Android 新建Module的默认布局方式

这里是将默认的ConstraintLayout 修改为了LinearLayout

模板文件保存路径为:

D:\Program Files\JetBrains\IntelliJ IDEA 2020.3.4\plugins\android\lib\templates\activities\common\root\res\layout\simple.xml.ftl

 修改前:

<?xml version="1.0" encoding="utf-8"?>
<${getMaterialComponentName('android.support.constraint.ConstraintLayout', useAndroidX)}
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
<#if appBarLayoutName??>
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/${appBarLayoutName}"
</#if>
    tools:context="${packageName}.${activityClass}">

<#if isNewModule!false>
    <TextView
<#if includeCppSupport!false>
        android:id="@+id/sample_text"
</#if>
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</#if>
</${getMaterialComponentName('android.support.constraint.ConstraintLayout', useAndroidX)}>

修改后:

<?xml version="1.0" encoding="utf-8"?>
<${getMaterialComponentName('LinearLayout', useAndroidX)}
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	android:orientation="vertical"
<#if appBarLayoutName??>
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/${appBarLayoutName}"
</#if>
    tools:context="${packageName}.${activityClass}">


</${getMaterialComponentName('LinearLayout', useAndroidX)}>

省去了每次创建模块后手工修改的麻烦,当然,您想创建的时候自动生成什么东西也是可以在这里预定义的。包括其它自动生成的文件。比如styles.xml. color.xml....

猜你喜欢

转载自blog.csdn.net/wh445306/article/details/129543788