找不到与给定名称 Theme.AppCompat.Light.NoActionBar 匹配的资源。

16

我正在向Styles.xml文件中添加一些项目,但是出现了错误。

以下是我的代码。

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#2196F3</item>
        <item name="drawerArrowStyle">@style/MyDrawerArrowStyle</item>
    </style>
    <style name="MyDrawerArrowStyle"   parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="color">#F5F5F5</item>
        <item name="spinBars">true</item>
    </style>
</resources>

以下是屏幕截图中显示的错误:

error screenshot

  1. 无法检索到父项:没有找到与给定名称'Theme.AppCompat.Light.NoActionBar'匹配的资源。
  2. 没有找到与给定名称'colorPrimary'匹配的资源。
  3. 没有找到与给定名称'drawerArrowStyle'匹配的资源。
  4. 没有找到与给定名称'Widget.AppCompat.DrawerArrowToggle'匹配的资源。
  5. 没有找到与给定名称'color'匹配的资源。
  6. 没有找到与给定名称'spinBars'匹配的资源。
4个回答

15

对于我下载的项目,没有有效的引用。我从NuGet商店安装了Xamarin.Android.Support.v4Xamarin.Android.Support.v7.AppCompat和其他一些引用。现在应用程序可以编译了。 - testing

2

我记不清楚 Theme.AppCompat.Light.NoActionBar 是否存在。

你可以尝试使用以下方式替代:

<style name="MyTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">#2196F3</item>
    <item name="drawerArrowStyle">@style/MyDrawerArrowStyle</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

1
以下是解决这些问题的步骤:
  1. 进入AndroidManifest.xml文件,在uses-sdk标签下添加android:targetSdkVersion为23。
  2. 进入项目 -> 通用,将目标框架设置为Android 6.0(Marshmallow)。
  3. 进入项目 -> Android应用程序 -> 将目标Android版本设置为Android 6.0。

最新的Xamarin Studio中没有编译Android 7.0版本。现在只能编译Android 6.0版本的Android项目。


我不认为这还是现实情况。 - shortstuffsushi

1
add component Support Library v7 AppCompat 

create values/styles and add
<?xml version="1.0" encoding="utf-8" ?>
<resources>

  <style name="MyTheme" parent="MyTheme.Base">
  </style>
  <style name="MyTheme.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 http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <!-- 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. -->
  </style>
</resources>

add another folder values-v21
create styles.xml and add
<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <!--
        Base application theme for API 21+. This theme replaces
        MyTheme from resources/values/styles.xml on API 21+ devices.
    -->
  <style name="MyTheme" parent="MyTheme.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
  </style>
</resources>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接