Steve Waring
Steve Waring

Reputation: 3023

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.

Upvotes: 5

Views: 5550

Answers (1)

codezjx
codezjx

Reputation: 9142

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"

Upvotes: 4

Related Questions