问题描述
我有一个使用 Preferences API
创建的首选项屏幕。我添加了一个自定义布局,我需要在其中存储我的首选项。这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_preferences"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Some code -->
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<!-- required ViewGroup for PreferenceFragmentCompat -->
<FrameLayout
android:id="@android:id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="NewApi" />
</LinearLayout>
因此在 frameLayout
中,我稍后会添加我的偏好。我在样式中将此视图膨胀为我的首选项屏幕的默认视图。
<style name="PreferenceThemeStyle" parent="@style/PreferenceThemeOverlay">
<item name="android:layout">@layout/fragment_preferences</item>
</style>
在我的基本主题中
<item name="preferenceTheme">@style/PreferenceThemeStyle</item>
我有一些样式,我需要在styles-v26 中为android 8 及更高版本定义这些样式。所以我还有一个文件 styles-v26
。现在,当我尝试在 android 8 或更高版本中打开我的首选项屏幕时,它崩溃了。崩溃问题在于这些样式。复制此行并将其放入 style-v26 后,一切正常。
<item name="preferenceTheme">@style/PreferenceThemeStyle</item>
但据我所知,如果我没有在 v26 中定义这个样式,它必须从默认的 styles.xml 中获取。那么为什么它不从默认的 styles.xml 中获取它呢?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)