Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button with custom background and "?attr/selectableItemBackground"

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"/>
like image 349
MarcGV Avatar asked Mar 13 '17 11:03

MarcGV


1 Answers

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>
like image 194
Paresh P. Avatar answered Oct 06 '22 00:10

Paresh P.