找不到与给定名称匹配的资源 Theme.AppCompat.Light.NoActionBar
No resource found that mach the given name Theme.AppCompat.Light.NoActionBar
我正在 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>
错误可以在下面的截图中看到
- 检索项目的父项时出错:找不到与给定名称匹配的资源 'Theme.AppCompat.Light.NoActionBar'。
- 找不到与给定名称匹配的资源:attr 'colorPrimary'。
- 找不到与给定名称匹配的资源:attr 'drawerArrowStyle'。
4..找不到与给定名称匹配的资源 'Widget.AppCompat.DrawerArrowToggle'.
- 找不到与给定名称匹配的资源:attr 'color'。
- 找不到与给定名称匹配的资源:attr 'spinBars'。
我不记得 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>
我通过在我的 xamarin studio android 项目的包中添加 AppCompact v7 找到了我的解决方案。
Link=https://components.xamarin.com/view/xamandroidsupportv7appcompat
以下是解决这些问题的步骤;
- 转到AndroidManifest.xml并在uses-sdk标签下将android:targetSdkVersion添加到23。
- 转到项目 -> 常规并将目标框架设置为 Android 6.0 (Marshmallow)。
- 转到项目 -> Android 应用程序 -> 将目标 Android 版本设置为 Android 6.0。
Android 版本 7.0 未在最新的 Xamarin Studio.Right 中编译,现在您只能编译 Android 项目到 Android 6.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>
我正在 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>
错误可以在下面的截图中看到
- 检索项目的父项时出错:找不到与给定名称匹配的资源 'Theme.AppCompat.Light.NoActionBar'。
- 找不到与给定名称匹配的资源:attr 'colorPrimary'。
- 找不到与给定名称匹配的资源:attr 'drawerArrowStyle'。 4..找不到与给定名称匹配的资源 'Widget.AppCompat.DrawerArrowToggle'.
- 找不到与给定名称匹配的资源:attr 'color'。
- 找不到与给定名称匹配的资源:attr 'spinBars'。
我不记得 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>
我通过在我的 xamarin studio android 项目的包中添加 AppCompact v7 找到了我的解决方案。
Link=https://components.xamarin.com/view/xamandroidsupportv7appcompat
以下是解决这些问题的步骤;
- 转到AndroidManifest.xml并在uses-sdk标签下将android:targetSdkVersion添加到23。
- 转到项目 -> 常规并将目标框架设置为 Android 6.0 (Marshmallow)。
- 转到项目 -> Android 应用程序 -> 将目标 Android 版本设置为 Android 6.0。
Android 版本 7.0 未在最新的 Xamarin Studio.Right 中编译,现在您只能编译 Android 项目到 Android 6.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>