Xamarin Android此活动已经具有窗口装饰提供的操作栏

问题描述 投票:0回答:1

我看过很多关于此的帖子,但到目前为止,对我来说没有任何帮助。我得到的完整错误是:

此活动已经具有窗口装饰提供的操作栏。不要在您的主题中请求Window.FEATURE_SUPPORT_ACTION_BAR并将windowActionBar设置为false来代替使用工具栏。

我们升级了Android软件包,这导致了这种情况的发生。

这是我的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

我的样式如下:

  <?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>

android xamarin.android
1个回答
0
投票

首先,windowActionBarandroid:windowActionBar不同。

AppCompat东西看的是应用程序名称空间属性,而不是android。这样,即使在最初没有属性的平台中,也可以指定该属性。这就是它允许向后移植colorPrimary之类的内容的方式。

[请注意,您的MainTheme.Base具有此注释<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->,如果在22.1支持库之后使用AppCompatActivity,则应删除android:

您的style.xml的代码,类似于以下代码。

  <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>
© www.soinside.com 2019 - 2024. All rights reserved.