找不到资源名称为Theme.AppCompat.Light.NoActionBar的资源

时间:2015-10-12 11:45:18

标签: xamarin.android xamarin-studio

我在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. 找不到与给定名称匹配的资源:attr'colorPrimary'。
  3. 找不到与给定名称匹配的资源:attr'drawerArrowStyle'。 4 ..找不到与给定名称“Widget.AppCompat.DrawerArrowToggle”匹配的资源。
  4. 找不到与给定名称匹配的资源:attr'color'。
  5. 找不到与给定名称匹配的资源:attr'spinBars'。

4 个答案:

答案 0 :(得分:14)

我通过在我的xamarin工作室android项目的包中添加AppCompact v7找到了我的解决方案。

Link = https://components.xamarin.com/view/xamandroidsupportv7appcompat

答案 1 :(得分:1)

我不记得首先是否存在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>

答案 2 :(得分:1)

以下是解决这些问题的步骤;

  1. 转到AndroidManifest.xml并在uses-sdk标记下将android:targetSdkVersion添加到23。
  2. 转到项目 - &gt;一般并将Target框架设置为Android 6.0(Marshmallow)。
  3. 转到项目 - &gt; Android应用程序 - &gt;将目标Android版本设置为Android 6.0。
  4. Android版7.0不是在最新的Xamarin Studio中编译的。现在你只能将Android项目编译到Android 6.0。

答案 3 :(得分:0)

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>
相关问题