Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead

喜你入骨 提交于 2019-11-27 02:16:14

问题


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 name="ToolBarStyle" parent="@style/Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>       

 </style> 

I tried parent="@style/Theme.AppCompat.Light.NoActionBar" but not worked.

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

    <application android:label="Capzure" android:theme="@style/ToolBarStyle" android:icon="@drawable/Icon"></application>

Thank you.


回答1:


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>

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.

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" 


来源:https://stackoverflow.com/questions/30669926/do-not-request-window-feature-action-bar-and-set-windowactionbar-to-false-in-you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!