我正在使用PreferenceFragmentCompat作为我的“首选项”页面
public class SettingsFragment extends PreferenceFragmentCompat{
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.pref_page, rootKey);
} }
并且我正在使用此主题作为我的Activity,该主题设置了我的PreferenceFragmentCompat:
<style name="SettingsTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/text_color</item>
<item name="android:windowBackground">@color/colorPrimaryDarkBackground</item>
<item name="android:textColorPrimary">@color/text_color</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
但是我的“首选项页面”看起来像这样: Preference Page
然后我添加了自定义样式:
<style name="SettingsTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/text_color</item>
<item name="android:windowBackground">@color/colorPrimaryDarkBackground</item>
<item name="android:textColorPrimary">@color/text_color</item>
<item name="preferenceTheme">@style/PreferenceThemeCustom</item>
<style name="PreferenceThemeCustom" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/text_color</item>
<item name="android:windowBackground">@color/colorPrimaryDarkBackground</item>
<item name="android:textColorPrimary">@color/text_color</item>
<item name="android:divider">@color/text_color</item>
</style>
所有显示都很好like this 但是当我单击EditTextPreference时,出现以下错误:
Fatal Exception: java.lang.IllegalStateException: Dialog view must contain an EditText with id @android:id/edit
at androidx.preference.EditTextPreferenceDialogFragmentCompat.onBindDialogView(EditTextPreferenceDialogFragmentCompat.java:68)
at androidx.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:149)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:352)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1383)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:887)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1233)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1299)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:688)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2069)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1859)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1814)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1721)
at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManagerImpl.java:147)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
然后我试图定义我的自定义首选项样式:
<style name="PreferenceThemeCustom" parent="PreferenceThemeOverlay.v14.Material">
<item name="android:textColor">@color/text_color</item>
<item name="android:windowBackground">@color/colorPrimaryDarkBackground</item>
<item name="android:textColorPrimary">@color/text_color</item>
<item name="android:divider">@color/text_color</item>
</style>
但是设置parent =“ PreferenceThemeOverlay.v14.Material”再次导致了此问题:Preference Page
答案 0 :(得分:0)
将<android:windowBackground="...">
替换为<android:background="...">
,我想应该有帮助