找不到 Xamarin 中 Android 的自定义主题

Custom theme for Android in Xamarin not being found

我正在使用 Visual Studio。

在我的 MainActivity.cs 文件中,我试图设置自定义主题。 Activity 属性如下所示:[Activity(Label = "MyTest", Icon = "@drawable/icon", Theme = "@android:style/Theme.Idkred", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

当我尝试构建时,我得到:error APT0000: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.Idkred').

我的 Android 资源文件夹中有一个值文件夹。里面有一个 styles.xml 文件。 styles.xml 文件的构建操作是 AndroidResource.

看起来它正在处理中,因为在构建输出中我看到 Processing: obj\Debug\res\values\styles.xml

我的 styles.xml 文件有这个:

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <style name="Theme.Idkred" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_idkred</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Idkred</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Idkred</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Idkred</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Idkred</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Idkred</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_idkred</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_idkred</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Idkred</item>
    </style>

... (more styles)
</resources>

您必须删除 android: 命名空间。

[Activity(Label = "MyTest", Icon = "@drawable/icon", Theme = "@style/Theme.Idkred", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

此命名空间仅适用于来自Android它自身的资源。