Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

android - How to use ActionBarActivity with Theme.Material

I created a new project targeting the L preview. The starter activity that the sdk generates extends ActionBarActivity, however, when I try to run the bare-bone generated activity, it throws the following exception:

  Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
            at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)

I've looked around but Theme.AppCompat.Material doesn't seem to exist. How do I make ActionBarActivity to take advantage of the new Material themes?

My build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.sdchang.example'
        minSdkVersion 'L'
        targetSdkVersion 'L'
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.mcxiaoke.volley:library:1.0.+@aar'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.squareup.okhttp:okhttp:2.0.+'
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

AppCompat v21.+'s Theme.AppCompat extends Theme.Base.AppCompat which extends Theme.Platform.AppCompat which extends android:Theme.Material on 21+ devices (i.e., Android L) devices so you shouldn't have to do anything specific to get the Material theme if you are using AppCompat.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...