?android:attr/selectableItemBackground在白色windowBackground上无效。

4

我想要使用

?android:attr/selectableItemBackground

我希望你能翻译一下我的RecyclerView项目相关的内容。不幸的是,它似乎无法正常工作。我在styles.xml文件中添加了以下行:

<item name="android:windowBackground">@color/white</item>

如果没有这行代码,我可以看到水波纹效果,这意味着由于白色的windowBackground而导致背景无法工作。我该如何强制水波纹效果出现在我的白色背景上?

以下是recyclerview项目的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/brand_row"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_marginLeft="@dimen/activity_horizontal_margin"
              android:layout_weight="1"
              android:gravity="center_vertical"
              android:orientation="vertical">

    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textColor="@color/modelTitelColor"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/numbers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textColor="@color/cardview_background"
        android:textStyle="normal"/>
</LinearLayout>


<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/divider"/>
</LinearLayout>

我的最低SDK版本是14

1个回答

4

在我的styles.xml文件中,我正在使用

Theme.AppCompat.NoActionBar 

作为父主题。将其更改为

style name="CustomMaterialTheme" parent="Theme.AppCompat.Light.NoActionBar"

解决了问题。现在我可以看到效果。

这对我很有用!我试图定义一个扩展Theme.MaterialComponents.Dialog的自定义样式,但所有的selectableItemBackgrounds都不再可见。使用Theme.AppCompat.Light.Dialog解决了所有问题。 - reavcn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接