locked
Java.Lang.IllegalStateExcep:'This Activity already has an action bar supplied by the window decor. RRS feed

  • Question

  • User364101 posted

    Hi, I ran into a problem while updating the Xamarin.Android Project. I am getting this error

    Java.Lang.IllegalStateException: 'This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURESUPPORTACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.'

    And the snaps of style sheet..

      <style name="PoppinsTheme" parent="PoppinsTheme.Base">
    </style>
    
    <!-- Base theme applied no matter what API -->
    <style name="PoppinsTheme.Base" parent="@style/Theme.AppCompat.Light">
      <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
     <item name="colorPrimary">@color/primary</item>
     <item name="android:textColorPrimary">@color/white</item>
      <item name="colorPrimaryDark">@color/primary_dark</item>
      <item name="colorAccent">@color/accent</item>
     <item name="android:windowBackground">@color/primary</item>
      <item name="android:editTextStyle">@style/PoppinsTheme.EditText</item>
       <item name="listPopupWindowStyle">@style/PoppinsTheme.EllipsisMenu</item>
       <item name="android:textColorSecondary">@color/black</item>
       <item name="android:itemTextAppearance">@style/MenuActions</item>
     </style>
    
    <style name="PoppinsTheme.EllipsisMenu" parent="@style/Widget.AppCompat.Light.ListPopupWindow">
      <item name="android:popupBackground">@color/primary</item>
    </style>
    
    <style name="PoppinsTheme.Login" parent="@style/PoppinsTheme">
        <!--<item name="android:windowBackground">@drawable/DaillyPoppins_Logo_White_500px</item>-->
       <item name="windowNoTitle">true</item>
      <item name="windowActionBar">false</item>
       <item name="android:windowFullscreen">true</item>
      </style>
    
     <style name="PoppinsTheme.ActionBarVisible" parent="@style/PoppinsTheme">
       <item name="windowNoTitle">false</item>
       <item name="windowActionBar">false</item>
       <item name="android:windowFullscreen">true</item>
     </style>
    
     <style name="PoppinsTheme.Splash" parent="@style/PoppinsTheme">
      <item name="windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
     </style>
    
     <style name="PoppinsTheme.ActionBarStyle" parent="@style/PoppinsTheme">
     <item name="android:background">@color/navigation</item>
     </style>
    
     <style name="MenuLabelsStyle">
       <item name="android:textColor">@color/white</item>
       <item name="android:textSize">14sp</item>
      <item name="android:maxLines">2</item>
       <item name="android:ellipsize">end</item>
      </style>
    
    <style name="MenuButtonsStyle">
        <item name="fab_size">mini</item>
      <item name="fab_showAnimation">@anim/jump_from_down</item>
      <item name="fab_hideAnimation">@anim/jump_to_down</item>
      <item name="fab_shadowColor">#444</item>
      <item name="fab_colorNormal">@color/gray_floating_button_color</item>
       <item name="fab_colorPressed">@color/gray_floating_button_color_darker</item>
       <item name="fab_colorRipple">@color/gray_floating_button_color_darker_ripple</item>
     </style>
    
      <style name="AlertDialogCustom" parent="@style/Theme.AppCompat.Light.Dialog.Alert">
       <!-- your app branding color for the app bar -->
        <item name="colorPrimary">@color/primary_dark</item>
       <!-- darker variant for the status bar and contextual app bars -->
       <item name="colorPrimaryDark">@color/primary_dark</item>
        <!-- theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">@color/primary_dark</item>
      </style>
    
      <style name="PoppinsTheme.EditText" parent="@style/Widget.AppCompat.EditText">
      <item name="android:textColor">@color/white</item>
      <item name="android:textSize">18sp</item>
     <item name="android:paddingTop">10dp</item>
     <item name="android:paddingBottom">10dp</item>
      <item name="android:textColorHint">@color/white</item>
     </style>
    
    <style name="PoppinsTheme.RadioButton" parent="Theme.AppCompat.Light">
       <item name="colorAccent">@color/white</item>
       <item name="colorControlHighlight">@color/white</item>
        <item name="android:colorPressedHighlight">@color/white</item>
        <item name="colorPrimaryDark">@color/white</item>
        <item name="colorPrimary">@color/white</item>
        <item name="colorControlActivated">@color/white</item>
        <item name="colorControlNormal">@color/white</item>
      </style>
    
    
    <style name="MenuActions">
       <item name="android:textColor">@color/black</item>
       <item name="android:actionMenuTextColor">@color/white</item>
       <item name="actionMenuTextColor">@color/white</item>
    </style>
    

    Please #Help.

    Friday, November 1, 2019 4:59 AM

Answers

  • User382871 posted

    To display the custom toolbar, the default ActionBar must be disabled. You need to set the windowActionBar to flase in styles.xml and specify the Theme for Activity. Activity.cs ``` [Activity(Label = "Activity1", Theme = "@style/AppTheme.NoActionBar")] public class Activity1 : AppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.layout2);

        Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);
    
        ...
    }
    

    } styles.xml ```

    Tutorial about Replacing the Action Bar: https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/tool-bar/replacing-the-action-bar

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, November 1, 2019 7:53 AM