问题描述
当我将工具栏应用到我的应用程序时遇到了这个问题,当我尝试运行该应用程序时它崩溃了.我使用了以前的所有文章,但没有运气. 这是我的代码:
I'm having this issue when I applied the toolbar into my app and it crashed when I try to run the app.I used all previous post but no luck. Here is my code :
Style.xml
Style.xml
<style name="ToolBarStyle" parent="@style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
我尝试了parent ="@ style/Theme.AppCompat.Light.NoActionBar",但没有用.
I tried parent="@style/Theme.AppCompat.Light.NoActionBar" but not worked.
Toolbar.xmal
Toolbar.xmal
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolBarStyle" />
Manifest.axml
Manifest.axml
<application android:label="Capzure" android:theme="@style/ToolBarStyle" android:icon="@drawable/Icon"></application>
谢谢.
推荐答案
您的主题应如下所示,并删除@style/
:
Your theme should look like this, and remove @style/
:
<style name="MyMaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
...
</style>
然后,不要在<application/>
标记中定义主题.仅在要使用材质设计主题的活动中定义它,即在<activity>
标签中.
Then, do not define the theme in <application/>
tag. Define it only with activity you want to use the material design theme, i.e. in <activity>
tag.
如果您的活动扩展了PreferenceActivity
,AppCompatActivity
或ActionBarActivity
,而您想从PreferenceFragment
开始交易,请将您的主题更改为:
If your activity extends PreferenceActivity
, AppCompatActivity
, or ActionBarActivity
, which you want to begin the transaction with PreferenceFragment
, change your theme to:
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
并从工具栏中删除此行:
And remove this line from your Toolbar:
android:theme="@style/ToolBarStyle"
这篇关于不要请求Window.FEATURE_ACTION_BAR并将主题中的windowActionBar设置为false来使用工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!