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

32,873

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" 
Share:
32,873
Uddhao Pachrne
Author by

Uddhao Pachrne

Updated on July 05, 2022

Comments

  • Uddhao Pachrne
    Uddhao Pachrne almost 2 years

    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.