Fernando Santos
Fernando Santos

Reputation: 432

AppCompatActivity as Default in Android Studio

I'd like to know the reason my android studio (version 1.5.0) extends AppCompatActivity instead Activity by default, even I chose min API level as 19 and I don't know if it helps.

Android Studio warns about deprecated methods of other APIs (e.g.: Android Studio warns that navigation mode is deprecated in API 21, but I'm using API 19 (and I want to use only it)).

Upvotes: 1

Views: 1516

Answers (2)

wrkwrk
wrkwrk

Reputation: 2351

Appcompat is set by the android studio project templates.

The templates path is [android-studio-path]/plugins/android/lib/templates. When creating a new activity, it will include a config file: activities/common/common_globals.xml.ftl, it looks like this:

<#assign theme=getApplicationTheme()!{ "name": "AppTheme", "isAppCompat": true }>
<#assign themeName=theme.name!'AppTheme'>
<#assign themeNameNoActionBar=theme.nameNoActionBar!'AppTheme.NoActionBar'>
<#assign appCompat=theme.isAppCompat!false>
<#assign appCompatActivity=appCompat && (buildApi gte 22)>  
...
<global id="appCompat" type="boolean" value="${((isNewProject!false) || (theme.isAppCompat!false))?string}" />
<global id="appCompatActivity" type="boolean" value="${appCompatActivity?string}" />
...
<#if !appCompat>
<global id="superClass" type="string" value="Activity"/>
...
<#elseif appCompatActivity>
<global id="superClass" type="string" value="AppCompatActivity"/>
...

"appCompat" will be true if it's a new project or the project is using the appCompat theme(which is the default theme). So if the appCompat variable is set to false, it will use Activity by default.

<#assign appCompat=false>
<global id="appCompat" type="boolean" value="false" />

The style templates may need to be modified too, they are using the appCompat theme.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat<#if
        baseTheme?contains("light")>.Light<#if
        baseTheme?contains("darkactionbar")>.DarkActionBar</#if></#if>">

Note: If these files are modified, android studio will try to replace them with the default ones when updating to a new version.

Upvotes: 0

Jordy Cuan
Jordy Cuan

Reputation: 487

That is because AppCompatActivity gives compatibility to other API levels (under 15), this brings material design to older android versions. You can read more here Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?

Upvotes: 1

Related Questions