Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the template that Android Studio uses to create a blank activity

I would like to change the template so that the new activity uses AppCompatActivity instead of the depreciated ActionBarActivity

I found sdk\tools\templates\activities\BlankActivity\root\src\app_package\SimpleActivity.java.ftl and after making a backup copy I changed

import <#if appCompat>android.support.v7.app.ActionBarActivity<#else>android.app.Activity</#if>;

to

import <#if appCompat>import android.support.v7.app.AppCompatActivity<#else>android.app.Activity</#if>;

and

public class ${activityClass} extends ${(appCompat)?string('ActionBar','')}Activity {

to

public class ${activityClass} extends ${(appCompat)?string('AppCompat','')}Activity {

but when I create a new activity it still uses ActionBarActivity.

like image 778
Steve Waring Avatar asked Sep 28 '22 22:09

Steve Waring


1 Answers

I just change two position:

1.import <#if appCompat>android.support.v7.app.AppCompatActivity<#else>android.app.Activity;

2.public class ${activityClass} extends ${(appCompat)?string('AppCompat','')}Activity {

And it's work for me!

I see you code, your first edit has one more "import" string. -_-|||

Edit: By the way, I edit SimpleActivity.java.ftl under Android-Studio folder:"X:\xxxx\android-studio\plugins\android\lib\templates\activities\BlankActivity\root\src\app_package"

like image 185
codezjx Avatar answered Oct 06 '22 01:10

codezjx