This Activity already has an action bar supplied by the window decor

后端 未结 21 2317
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:45

Trying to move over my stuff to use Toolbar instead of action bar but I keep getting an error saying

java.lang.RuntimeException: Unable to start         


        
相关标签:
21条回答
  • 2020-11-22 00:23

    Simply put, you can do the following:-

    if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    
        }
    
    0 讨论(0)
  • 2020-11-22 00:24

    I had toolbar added in my xml. Then in my activity i was adding this statement:

    setSupportActionBar(toolbar);
    

    Removing this worked for me. I hope it helps someone.

    0 讨论(0)
  • 2020-11-22 00:27

    Add this two line in your app theme located in style.xml:-

     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    
        //Add this two line will fix your problem
        <item name="windowNoTitle">true</item>   <--1(this applies after 22.0.1 support library i think 
        <item name="windowActionBar">true</item> <--2
    

    0 讨论(0)
  • 2020-11-22 00:28

    Use this inside your application tag in manifest or inside your Activity tag.

    android:theme="@style/AppTheme.NoActionBar"

    0 讨论(0)
  • 2020-11-22 00:29

    Or Simply change the @Style/AppTheme

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    

    This works for me!

    0 讨论(0)
  • 2020-11-22 00:30

    Go to the 'style.xml' of your project and make windowActionBar to false

    <style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
            <item name="android:windowActionBar">false</item>
    </style>
    
    0 讨论(0)
提交回复
热议问题