【问题标题】:No resource found that mach the given name Theme.AppCompat.Light.NoActionBar找不到与给定名称 Theme.AppCompat.Light.NoActionBar 匹配的资源
【发布时间】:2015-10-12 11:45:18
【问题描述】:

我在 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>

错误可以在下面的截图中看到

  1. 检索项目的父项时出错:找不到与给定名称“Theme.AppCompat.Light.NoActionBar”匹配的资源。
  2. 找不到与给定名称匹配的资源:attr 'colorPrimary'。
  3. 找不到与给定名称匹配的资源:attr 'drawerArrowStyle'。 4..找不到与给定名称“Widget.AppCompat.DrawerArrowToggle”匹配的资源。
  4. 未找到与给定名称匹配的资源:attr 'color'。
  5. 找不到与给定名称匹配的资源:attr 'spinBars'。

【问题讨论】:

    标签: xamarin.android xamarin-studio


    【解决方案1】:

    我通过在我的 xamarin studio android 项目的 Package 中添加 AppCompact v7 找到了我的解决方案。

    链接=https://components.xamarin.com/view/xamandroidsupportv7appcompat

    【讨论】:

    • 对于我下载的项目,没有有效的参考。我从 NuGet 商店安装了 Xamarin.Android.Support.v4Xamarin.Android.Support.v7.AppCompat 和一些其他参考资料。现在应用程序编译。
    【解决方案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>
    

    【讨论】:

      【解决方案3】:

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

      1. 进入AndroidManifest.xml,在uses-sdk标签下添加android:targetSdkVersion到23。
      2. 转到 Project -> General 并将 Target framework 设置为 Android 6.0 (Marshmallow)。
      3. 转到项目 -> Android 应用程序 -> 将目标 Android 版本设置为 Android 6.0。

      最新的 Xamarin Studio 中未编译 Android 7.0 版本。目前您只能将 Android 项目编译到 Android 6.0。

      【讨论】:

      • 我认为不再是这种情况了。
      【解决方案4】:
      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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 2017-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多