Skip to content
Advertisement

Why I see Do not request Window.FEATURE_SUPPORT_ACTION_BAR?

This is a simple app with a tag navigation. And I can’t open it with getting a mistake. A part of it is:

Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
    at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:572)
    at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:159)
    at com.example.tabexperiment.MainActivity.onCreate(MainActivity.java:29)

And here is a 28-th and 29-th lines in MainActivity(the message above says mistake is in 29-th line):

androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

I tried to cope with the problem but all what I found is that I should add this code in themes file:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

and this line in Manifest:

android:theme="@style/Theme.TabExperiment"

So, I have that in my code but nothing is still working. Help me, please.

Advertisement

Answer

you can use this:

<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
</style>

OR

<activity android:name=".activity.YourActivity"
          android:theme="@style/AppTheme.NoActionBar"/>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement