我正在尝试实现一个使用 Android 的默认 itemBackground 样式的 View (但具有椭圆形背景,用于操作栏项目等)。不知何故,下面的 View 根本没有显示背景。如果我将 android:background 更改为 android:foreground 它只显示矩形而不是椭圆形。有人知道如何解决这个问题吗?
<LinearLayout
app:visibleGone="@{showProfile}"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<ImageView
android:background="?selectableItemBackgroundBorderless"
android:layout_width="24dp"
android:layout_height="24dp"
android:onClick="@{() -> profileCallback.onClick()}"
android:src="@drawable/profile_image" />
</LinearLayout>
最佳答案
您的代码是正确的,但棘手的是父布局也需要背景。
尝试将 android:background="@android:color/transparent"
或任何其他背景设置为其父背景。在您的例子中,它是 LinearLayout。
关于android - ?selectableItemBackgroundBorderless 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45513451/