片段和其他模板的Android Studio向导 [英] Android Studio wizard for Fragments and other templates

查看:103
本文介绍了片段和其他模板的Android Studio向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在Android Studio中为该项目创建一个新的Fragment时,它都会创建 android.support.v4.app.Fragment ,这不是我想要的.另外,它始终会触发gradle更新.使用向导创建新片段并摆脱gradle更新时,如何将默认片段设置为 android.app.Fragment ?

Every time I create a new Fragment in my Android Studio for the project, it creates android.support.v4.app.Fragment, which is not what I want. Also, it alsways triggers a gradle update. How to set default Fragment to android.app.Fragment when creating new one with wizard and get rid of gradle updates?

推荐答案

供将来的读者使用!

正如在注释中提到的CommonsWare更改模板一样,它可能不会持续更长时间,因为Android Studio更新可能会覆盖它们.因此,您可以按照以下文章中的说明创建自己的自定义文件模板.

As CommonsWare mentioned in comments changing the templates may not last longer as Android Studio updates may overwrite them. So you may create your own custom file templates as described in following article.

https://riggaroo.co.za/custom-file- templates-android-studio/

在这里您可能必须创建两个文件模板

Here you may have to create two file templates

  • 一个用于Fragment类
  • 另一个用于片段布局文件的

另一种更改片段模板的方法是备份要修改的原始文件,然后修改现有模板并备份修改后的模板,以便在Android Studio更新后恢复修改.

Another way to go about changing the fragment template is to backup the original files of that you are going modify and modify the existing templates and backup the modified templates in order to restore the modifications after an Android Studio update.

在修改之前备份原始文件非常重要,因为将来在更新android studio时,它会通知您有关文件被修改的信息,因此更新无法完成.因此,在更新android studio之前,您必须还原修改后文件的原始版本.

It's important to backup original files before modification, because when updating android studio in future, it will notify you about files being modified, so the update could not be completed. So you have to restore the original version of the modified files, before updating the android studio.

如果您需要更改片段模板(空白片段模板),请导航至

If you need to change Fragment template (Blank fragment template), navigates to

[android-studio-ndredirectory]/plugins/android/lib/templates/other/BlankFragment/root/src/app_package

并修改您选择的源文件. (BlankFragment.kt.ftlBlankFragment.java.ftl),以便修改 source 文件模板.

and modify the source file of your choice. (BlankFragment.kt.ftl or BlankFragment.java.ftl), in order to modify the source file template.

导航到

[android-studio directory]/plugins/android/lib/templates/other/BlankFragment/root/res/layout

并修改fragment_blank.xml.ftl,以修改布局文件模板.

and modify the fragment_blank.xml.ftl, in order to modify the layout file template.

进行修改后,您可以备份BlankFragment目录,以便在Android Studio更新后恢复所做的更改.

After doing your modifications, you may backup the BlankFragment directory, so you can restore your changes, after the Android Studio update.

这篇关于片段和其他模板的Android Studio向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆