在 Android Studio 提供的 "Bluetooth Le Gatt" 示例项目中,列表项如何变暗

How are listitems being darkened when touched in "Bluetooth Le Gatt" sample project provided by Android Studio

通过 Whosebug,我找到了关于如何在触摸列表项时使列表项变暗以便用户知道将要选择列表视图中的哪个项的答案。

How to change color of ListView items on focus and on click.

但是我在 Android Studios 提供的蓝牙 Le Gatt 示例项目中找不到该类型功能的任何类型的实现。

我使用我的可绘制文件夹中的 xml 文件为我的列表项设置了背景,这些背景将它们的颜色从普通的白色更改了。这防止列表项在触摸时变暗。

编辑:您还可以将背景设置为可选,以便在 selected/pressed 时产生效果。

android:background="?android:attr/selectableItemBackground"