如何在 Android Studio 中更改默认模板布局文件
正如您所知,每次使用某个 Activity 创建新项目时,Android Studio 都会生成一个默认的 activity_main.xml 文件,其中 RelativeLayout 作为根元素和一个 TextView.但我更喜欢使用没有任何嵌套视图的 LinearLayout.如何更改 Android Studio 生成默认 activity_main.xml 的方式?
As you know every time you create new project with some activity, Android Studio generates a default activity_main.xml file with RelativeLayout as the root element and one TextView. But I prefer to use LinearLayout without any nested views. How can I change the way Android Studio generates the default activity_main.xml?
您可以通过编辑位于以下位置的默认模板文件来实现:
You can do that by editing default template files, which are located in:
...\Android\Android Studio\plugins\android\lib\templates\activities
例如,EmptyActivity模板的默认布局文件(注意:这个是特定的,其他的都有自己的res文件夹)位于:
so for example, default layout file for template of EmptyActivity (note: this one is specific, the other ones have their own res folders) is located in:
...\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout\simple.xml.ftl
通过在您最喜欢的文本编辑器中简单地将 RelativeLayout 替换为 LinearLayout,您就可以获得您想要的东西,但我建议您制作自己的模板,您可以在其中根据自己的需要定义任何字面意思.
by simply replacing RelativeLayout with LinearLayout in your favourite text editor, you get what you want, but instead of that, I recommend you to make your own template, where you can define literally anything, according to your desires.
有关 BlankActivity 和如何编辑其他模板的指南,请参阅此链接:如何更改 BlankActivity 模板默认文件以及如何为其他人执行此操作的指南.
For the BlankActivity and a guide how to edit the other templates see this link: How to change a BlankActivity template default files and a guide how to do it for any others.