How to define a Button
with custom background and the attribute "?attr/selectableItemBackground"
?
With this code the "?attr/selectableItemBackground"
attribute is ignored, it doesn't show the touch feedback.
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:foreground="?attr/selectableItemBackground"/>
With this other code the selectable works but I lose the background color:
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"/>
Alright you have an option of parent
Create parent and give background
to white color and use selectableItemBackground
as child's background.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"/>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With