Android工具栏错误

Android工具栏错误,android,android-toolbar,Android,Android Toolbar,我试图在应用程序中使用工具栏,但遇到了一个问题: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set android:windowActionBar to false in your theme to use a Toolbar instead.

我试图在应用程序中使用工具栏,但遇到了一个问题:

java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set android:windowActionBar to false in your theme to use a Toolbar instead.
我不相信我在任何地方请求Window.FEATURE\u ACTION\u栏,我正在将ActionBar设置为false。这是my Style.xml:

<resources>

<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
    <item name="android:textColor">@color/text</item>
    <item name="android:textColorPrimary">@color/text_primary</item>
    <item name="android:textColorSecondary">@color/text_secondary</item>
</style>

<style name="ToolbarTheme" parent="android:ThemeOverlay.Material.ActionBar">
    <item name="android:windowActionBar">false</item>
</style>

</resources>
这是我的toolbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:theme="@style/ToolbarTheme">

</Toolbar>

在我的布局中,我正在做,然后在onCreate中设置ActionBarToolBar。我已经看到多个线程关于这一点,但没有解决我的问题。我还应该注意,我只支持5.0,所以我没有使用appcompat,你必须在你的活动中使用这种风格,而不是在工具栏上

如果您未使用appCompat库:

<style name="AppTheme" parent="android:Theme.Material.Light">
   ....
   <item name="android:windowActionBar">false</item>
</style>

看这里:是的,我看到了那个线程,解决方案不适用于meThis false和这个false不一样。windowActionBar只在使用AppCompat时使用,就像我说的,我不是AAA,你是对的,对不起!我也试过了,但没用。起初,我只是使用我的AppTheme作为工具栏的主题,然后我将其更改为有自己的主题,并将android:windowActionBar同时放在两个工具栏中,而不是两个工具栏中worked@RyanSayles张贴你的舱单。你正在为你的活动设置样式吗?我有android:theme=@style/AppTheme>
<style name="AppTheme" parent="android:Theme.Material.Light">
   ....
   <item name="android:windowActionBar">false</item>
</style>