用于 Fragment 和其他模板的 Android Studio 向导 [英] Android Studio wizard for Fragments and other templates

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

问题描述

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

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-模板-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.

如果需要更改片段模板(Blank fragment template),导航到

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),以便修改源代码文件模板.

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,以修改layout文件模板.

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.

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

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