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

1

20

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.

Modification answered 5/6, 2015 at 15:8 Comment(0)
G
23

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" 
Grobe answered 5/6, 2015 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.