使用Theme.Material.Light.DarkActionBar与Theme.AppCompat.Light.DarkActionBar崩溃Android L上的应用程序(api v21)

时间:2014-11-26 17:56:06

标签: android android-appcompat material-design

以下是我的资源的样子

res/values/styles.xml
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">true</item>
    </style>

喜欢它说here

res/values-v21/styles.xml
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
    </style>

并且AndroidManifest.xml有

<application android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme" >

在我的MainActivity.java中,我从ActionBarActivity继承

public class MainActivity extends ActionBarActivity {
....
...
}

现在,当我在KitKat(API 19)上运行应用程序时,应用程序运行,我看到Dark Action栏和材料设计但是当我在Android L(API 21)上运行时,应用程序崩溃说java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 。我知道这是因为我继承自ActionBarActivity,但如果我在appcompat中使用values-v21/styles.xml主题,那么我将如何使用素材主题?

1 个答案:

答案 0 :(得分:6)

如果在Lollipop设备上运行,则

Theme.AppCompat从Material继承到Platform主题:在这种情况下,res/values-v21/styles.xml不是必需的。