[英]How to use android:Theme.Material and Toolbar together?
I am creating a android application where I am using Material Design components.I have used Material design theme(android:Theme.Material ), by extending my style with android:Theme.Material . 通过与Android延长我的风格:我创造,我现在用的材料设计components.I已使用材料的设计主题(Theme.Material机器人):一个Android应用程序Theme.Material。
<style name="MyMaterialTheme.Base" parent="android:Theme.Material.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/navigationBarColor</item>
<item name="android:displayOptions">disableHome</item>
</style>
Now, the issue is that I want to use toolbar also, but as I followed many tutorial I need to have Theme.AppCompat as my parent theme, if I want to use Toolbar. 现在,问题是我也想使用工具栏,但是当我遵循许多教程时,如果要使用工具栏,则需要将Theme.AppCompat作为父主题。
I tried with Material Design Theme, but throwing me the error as 我尝试了“材料设计主题”,但将错误抛出为
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
So, my question is, I can't use Material Design theme with Toolbar(as I am using Card Views also, so Material Design Theme is preferable) ? 所以,我的问题是,我不能在工具栏上使用Material Design主题(因为我也使用Card Views,因此Material Design Theme是更好的选择)?
Note:-I haveintegrated Toolbar using AppCompact theme, but I want to use Material Design theme only. 注意:-我已经使用AppCompact主题集成了工具栏,但是我只想使用Material Design主题。
将parent设置为“ @android:style / Theme.Material.Light.NoActionBar”,并在活动中使用AppCompatActivity。
You're getting 你正在
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
because your Activity
extends from AppCompatActivity
and to use it is mandatory that your activity theme must have a Theme.AppCompat or descendant. 因为您的Activity
从AppCompatActivity
扩展而来的,所以必须使用活动主题必须具有Theme.AppCompat或后代。
You could use Toolbar
in your activity without extending from AppCompatActivity
like this post refer. 你可以使用Toolbar
在你的活动,而从扩展AppCompatActivity
喜欢这个岗位参考。 But you still need a Theme.AppCompat
descendant. 但是您仍然需要Theme.AppCompat
后代。
BTW. BTW。 Why do you need specifically android:Theme.Material
? 为什么您特别需要android:Theme.Material
?
You need to update the theme in your manifest. 您需要更新清单中的主题。
Edit your theme entry to look like this: 编辑主题条目,如下所示:
android:theme="@style/Theme.AppCompat"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.