Do not request Window.FEATURE_ACTION_BAR issue

假装没事ソ 提交于 2019-11-27 08:38:37

Using Theme.AppCompat.Light tells Android that you want the framework to provide an ActionBar for you. However, you are creating your own ActionBar (a Toolbar), so you are giving the framework mixed signals as to where you want the ActionBar to come from.

Since you are using a Toolbar, you want Theme.AppCompat.Light.NoActionBar.

The next step is to make sure your Toolbar is styled correctly, which seems to be where you are running into issues. To style your Toolbar like an ActionBar using the colors you defined for your theme, you need to provide a theme like so:

<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

See the "styling" section for the Toolbar widget on this Android Developers blog post for more information.

Assuming you got this lines in styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

Add these extra lines after:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Then add this to your activity in manifest:

<activity android:name=".activity.YourActivity"
          android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->

That was best solution for me after checking tutorials and other solutions

In my case, I created a new activity and forgot to define it's app:theme in AndroidManifest.xml:

 <activity
        android:name=".HistoryActivity"
        android:label="History"
        android:theme="@style/AppTheme.Primary"></activity>

I have solved the problem after changing the value for the "android:theme" for the Activity in the manifest from "@style/AppTheme" to "@style/AppTheme.NoActionBar":

<activity android:name=".MyXXXActivity"
            ...                android:theme="@style/AppTheme.NoActionBar" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!