单击布局时快速灰色背景



我可以在某些Android应用程序中看到单击布局时快速出现和消失的灰色背景。 当我单击开关的"行"时,如何为带有文本的开关执行此操作(我想我必须在交换机的 xml 中添加一些内容(?

在视图背景中使用 selectableItemBackground

<Button
android:layout_width="match_parent" android:layout_height="45dp"
android:background="?selectableItemBackground"
android:text="UPDATE EMAIL"
android:padding="10dp"
android:gravity="center"
android:textColor="@color/white"
android:textSize="16dp"
android:id="@+id/btnContinue"/>

如果你的视图有自己的颜色,那么你应该使用?selectableItemBackground作为地面颜色,如下所示:

<Button
android:layout_width="match_parent" android:layout_height="45dp"
android:background="@color/colorPrimary"
android:foreground="?selectableItemBackground"
android:text="UPDATE EMAIL"
android:padding="10dp"
android:gravity="center"
android:textColor="@color/white"
android:textSize="16dp"
android:id="@+id/btnContinue"/>

最新更新