gpt4 book ai didi

android - 必须在主题中为 PreferenceFragmentCompat 指定 preferenceTheme

转载 作者:行者123 更新时间:2023-11-30 00:15:58 28 4
gpt4 key购买 nike

Android 开发新手,从 iOS 切换到黑暗面,请不要讨厌。

问题:我将 compile 'com.android.support:preference-v7:27.0.0' 添加到我的 Gradle。我在 styles.xml 中指定了一个主题。但是,我仍然收到如下所示的错误消息。如何解决这个问题?

java.lang.IllegalStateException: Must specify preferenceTheme in theme

at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:211)

引用文献:Stackoverflow answer , Medium article

设置 fragment

public class SettingsFragment extends PreferenceFragmentCompat {
private SwitchPreferenceCompat receiveReminders;
private ListPreference notifyMe;

@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);

receiveReminders = (SwitchPreferenceCompat) findPreference(R.string.key_receive_reminders);
notifyMe = (ListPreference) findPreference(R.string.key_notify_me);
}
}

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

preferences.xml

 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/settings_category_notifications">
<SwitchPreferenceCompat
android:key="@string/key_receive_reminders"
android:title="@string/settings_receive_reminders"
android:defaultValue="true"/>
<ListPreference
android:key="@string/key_notify_me"
android:title="@string/settings_notify_me"
android:summary="%s"
android:entries="@array/settings_notify_me_titles"
android:entryValues="@array/settings_notify_me_titles"
android:defaultValue="@string/notify_me_2_hours"
android:positiveButtonText="@null"
android:dependency="@string/key_receive_reminders"/>
</PreferenceCategory>
</PreferenceScreen>

最佳答案

确保在您的 AndroidManifest.xml 文件中为您的应用和/或 Activity 设置主题,否则将找不到 preferenceTheme:

<activity
android:name=".MainActivity"
android:theme="@style/AppTheme">
</activity>

关于android - 必须在主题中为 PreferenceFragmentCompat 指定 preferenceTheme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47277716/

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