以下是我的资源的样子
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
主题,那么我将如何使用素材主题?
答案 0 :(得分:6)
Theme.AppCompat
从Material继承到Platform主题:在这种情况下,res/values-v21/styles.xml
不是必需的。