在我的应用程序中,我尝试将android:Theme.Material
实现为样式values-21
文件夹中的父主题:
<!-- res/values-21/styles.xml -->
<resources>
<!-- your theme inherits from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- theme customizations -->
<item name="android:colorPrimary">@color/primary</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
<item name="android:navigationBarColor">@color/primary_dark</item>
</style>
</resources>
运行应用后,我的价格低于error
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
在values文件夹中。我有以下风格
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
但是,如果我在Theme.AppCompat.Light
中添加相同的values-21 folder
,那么它的工作正常。但是actionbar color
并没有改变。
为什么我不能在values-21 folder
中使用素材设计主题?
如何解决这个问题?
(注意:我的申请minsdk verison
为13
,maxsdk version
为22
)
我的活动扩展了AppCompactActivity
答案 0 :(得分:7)
您的应用主题在清单文件中定义:
/res/values/styles.xml
您会在<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
中找到此样式。
AppCompat
使用{{1}}即使对于早于Android 5.0的设备,也可以使用您的主题。主要的材料设计主题如下所示。
答案 1 :(得分:5)
如果您使用的是AppCompatActivity
,只需使用res/values/styles.xml
中的样式,并检查您用于colorPrimary,colorPrimaryDark的名称空间....
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>