问题描述
我的PreferenceFragmentCompat
中都有DrawerLayout
和带有NavigationView
的{{1}}。
我尝试使用MainActivity
更改项目背景。它可以在?selectableItemBackground
中的TextView
上运行。
NavigationView
(暗模式:深灰色,亮模式:白色)
但是它不适用于我的<TextView
android:id="@+id/feedback"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
... />
(始终为白色)。
这是我的主题,我使用自己的布局而不是默认的首选项布局。
我的活动主题。
PreferenceFragmentCompat
我的首选项布局。根是<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="preferenceTheme">@style/MyPreferenceTheme</item>
</style>
<style name="MyPreferenceTheme" parent="@style/PreferenceThemeOverlay">
<item name="preferenceScreenStyle">...</item>
<item name="preferenceFragmentCompatStyle">...</item>
<item name="preferenceFragmentStyle">...</item>
<item name="preferenceCategoryStyle">...</item>
<item name="preferenceStyle">@style/MyPreferenceStyle</item>
<item name="checkBoxPreferenceStyle">...</item>
<item name="switchPreferenceCompatStyle">...</item>
<item name="preferenceCategoryTitleTextAppearance">...</item>
<item name="switchPreferenceStyle">...</item>
<item name="dialogPreferenceStyle">...</item>
<item name="editTextPreferenceStyle">...</item>
<item name="preferenceFragmentListStyle">...</item>
</style>
<style name="MyPreferenceStyle">
<item name="android:layout">@layout/preference_item</item>
</style>
。
LinearLayout
我如何使其工作?
<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="wrap_content"
android:background="?selectableItemBackground"
android:baselineAligned="false"
android:clickable="true"
android:clipToPadding="false"
android:focusable="true"
...
解决方法
请在线性布局中给出完整的值。
android:background="?attr/selectableItemBackground"