selectableItemBackground在PreferenceFragmentCompat项目Androidx中不起作用

问题描述

我的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"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...