Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio wizard for Fragments and other templates

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?

like image 747
shadox Avatar asked Nov 09 '22 18:11

shadox


1 Answers

For future readers!

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

  • One for Fragment class
  • Another for fragment layout file

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.

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

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

Navigate to

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

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

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

like image 90
user158 Avatar answered Dec 20 '22 01:12

user158