0
votes

I've seen a bunch of posts about this but so far nothing has worked for me. The full error I get is:

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.

We upgraded the Android packages and it caused this to happen.

Here's my MainActivity

[Activity(Label = "MyApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

And my styles looks like this:

  <?xml version="1.0" encoding="utf-8" ?>

<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
  <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
  <item name="android:windowNoTitle">true</item>
  <!--We will be using the toolbar so no need to show ActionBar-->
  <item name="android:windowActionBar">false</item>
  <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
  <!-- colorPrimary is used for the default action bar background -->
  <item name="android:colorPrimary">#2196F3</item>
  <!-- colorPrimaryDark is used for the status bar -->
  <item name="android:colorPrimaryDark">#1976D2</item>
  <!-- colorAccent is used as the default value for colorControlActivated
       which is used to tint widgets -->
  <item name="android:colorAccent">#FF4081</item>
  <!-- You can also set colorControlNormal, colorControlActivated
       colorControlHighlight and colorSwitchThumbNormal. -->
  <item name="android:windowActionModeOverlay">true</item>

  <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="MainTheme.Splash" parent="Theme.AppCompat.Light.DarkActionBar">
  <item name="android:windowBackground">@drawable/splash</item>
  <item name="android:windowNoTitle">true</item>
</style>

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
  <item name="android:colorAccent">#FF4081</item>
</style>

1
You might wanna add the whole activity cs file code here otherwise we would just be speculating!FreakyAli

1 Answers

0
votes

First of all, windowActionBar not the same as android:windowActionBar.

AppCompat stuff looks at the app namespace attribute not the android one. This makes it possible to specify the attribute even in platforms that didn't originally have it. It's how it allows for backporting of things like colorPrimary.

Please notice your MainTheme.Base have this Comment <!--If you are using revision 22.1 please use just windowNoTitle. Without android:--> you should delete android:If you're using AppCompatActivity after 22.1 support library

Your code of style.xml like following code.

  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from https://aka.ms/material-colors -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>

  <style name="MainTheme.Splash" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
  </style>