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

后端 未结 21 2318
-上瘾入骨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:30

    There are two simple and quick solutions

    go to res-->values-->styles

    YOU can also watch this video for more easiness CLICK HERE

    Solution 1:

    You can remove the action bar by replacing

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    to

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    Solution2:

    Simply add these lines

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

    So now your style file look like this

    `

    <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>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    
    </style>
    

    `

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

    Just put parent="Theme.AppCompat.NoActionBar" in your style.xml file

    Like - <style parent="Theme.AppCompat.NoActionBar" name="AppTheme.NoActionBar">

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

    This is how I solved the problem. Add below code in your AndroidMainfest.xml

    <activity android:name=".YourClass"
                android:theme="@style/Theme.AppCompat.Light.NoActionBar">
     </activity>
    
    0 讨论(0)
  • 2020-11-22 00:33

    Add this in your values/styles.xml

    <style name="YourCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>
    
    <style name="AppBaseTheme" parent="YourCustomTheme">
    
    </style>
    
    <style name="AppTheme" parent="AppBaseTheme">
    
    </style>
    

    And add the following code in your values-v11/styles.xml and values-v14/styles.xml

    <style name="AppBaseTheme" parent="YourCustomTheme">
    
    </style>
    

    Thats it. It will work.

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

    If you get the error on this line:

    setSupportActionBar(...);
    

    You need to check if your activity is referring to a theme that contains a toolbar. Your application's AppTheme might already contain a toolbar, such as

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    

    and you are trying to add a second one. If you want to use your application's AppTheme, you need to remove the theme from your activity, in the manifest.xml file.

    For example:

    <activity
        android:name=".ui.activities.SettingsActivity"
        android:theme="@style/AppTheme1" /> --> remove this theme
    
    0 讨论(0)
  • 2020-11-22 00:38

    You need to change

      <activity
            android:name=".YOUR ACTIVITY"
            android:theme="@style/AppTheme.NoActionBar" />
    </application>`
    

    these lines in the manifest.It will perfectly work for me.

    0 讨论(0)
提交回复
热议问题