gpt4 book ai didi

android - CS0117 "Resource"不包含 "Xml"的定义

转载 作者:行者123 更新时间:2023-11-30 00:19:39 25 4
gpt4 key购买 nike

我创建了 settings.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_preferences_settings">
<android.support.v7.preference.PreferenceCategory android:title="Category 1">
<android.support.v7.preference.SwitchPreferenceCompat
android:key="key1"
android:title="Switch Preference"
android:summary="Switch Summary"
android:defaultValue="true" />
<android.support.v7.preference.EditTextPreference
android:key="key2"
android:title="EditText Preference"
android:summary="EditText Summary"
android:dialogMessage="Dialog Message"
android:defaultValue="Default value" />
<android.support.v7.preference.CheckBoxPreference
android:key="key3"
android:title="CheckBox Preference"
android:summary="CheckBox Summary"
android:defaultValue="true"/>
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>

在styles.xml中添加了preferenceTheme

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

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/ColorActionBar</item>
<item name="colorPrimaryDark">@color/ColorActionBar</item>
<item name="colorAccent">@color/accent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:listDivider">@color/background3</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

设置 fragment

using Android.OS;
using Android.Views;
using Android.Util;
using Android.Preferences;
using Android.Support.V7.Preferences;

namespace Aprepara.Droid.Activities.Fragments
{
public class SettingsFragment : PreferenceFragmentCompat
{
public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
{
AddPreferencesFromResource(Resource.Xml.settings);
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Log.Info("Aprepara.Droid", "SettingsFragment");
// Use this to return your custom view for this Fragment
return inflater.Inflate(Resource.Layout.settings, container, false);
}
}
}

但它显示资源中不存在 XML 的错误。

我正在使用这个例子作为引用......

https://components.xamarin.com/gettingstarted/xamandroidsupportpreferences?version=23.2.1

有人能帮帮我吗?为什么资源中不存在 XML?

enter image description here

最佳答案

but it is displaying the error that XML does not exist in Resource.

在您的Resource文件夹中创建一个xml文件夹,并将您的settings.xml放入这个xml文件夹中.

效果:

enter image description here

关于android - CS0117 "Resource"不包含 "Xml"的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46547704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com