fragment 和其他模板的 Android Studio 向导

标签 android android-fragments android-studio android-support-library

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

最佳答案

给 future 的读者!

正如 CommonsWare 在评论中提到的那样,更改模板可能不会持续更长时间,因为 Android Studio 更新可能会覆盖它们。因此,您可以创建自己的自定义文件模板,如下文所述。

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

在这里您可能需要创建两个文件模板

  • 一个 fragment 类
  • 另一个 fragment 布局文件


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

    修改前一定要备份原文件,因为以后更新android studio时,会通知你文件被修改,所以无法完成更新。所以你必须在更新android studio之前恢复修改文件的原始版本。

    如果您需要更改 fragment 模板(空白 fragment 模板),导航到
    [android-studio-ndredirectory]/plugins/android/lib/templates/other/BlankFragment/root/src/app_package
    

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

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

    并修改fragment_blank.xml.ftl ,为了修改布局文件模板。

    完成修改后,您可以备份 BlankFragment目录,这样您就可以在 Android Studio 更新后恢复您的更改。

    关于 fragment 和其他模板的 Android Studio 向导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964204/

    相关文章:

    android - ad-hoc 和 softAP WiFi 网络之间的根本区别是什么?

    android - android中的ActionBar和滑出菜单

    java - 将对象从 Fragment 的 GridView 传递到另一个 Fragment 的 ListView

    android - 添加 fragment 时无法解决

    android - 错误 :duplicate files during packaging of APK

    android - 在另一个事件中停止线程

    java - 自定义主题 android 崩溃由 : java. lang.IllegalStateException : You need to use a Theme. AppCompat 主题(或后代)与此 Activity 引起

    android - 如何动态更改 ViewPager 中的 fragment ?

    安卓工作室 : add virtual folder in gradle

    android - Gradle 无法构建 ActionBarSherlock