0

I use one button and i try to add two attrs in background property like add drawable xml and also want add ripple effect attrs "?attr/selectableItemBackground" Is it possible? My xml button code is here :-

 <Button android:id="@+id/btnRead"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:background="@drawable/readmcq"
         android:text="@string/readmcq"
         android:textAllCaps="false"
         android:textColor="@color/colorWhite"
         android:textSize="12sp" />

Can i try like this android:background="@drawable/readmcq" | "?attr/selectableItemBackground" ??

  • https://stackoverflow.com/questions/40008609/add-ripple-effect-to-my-button-with-button-background-color – Yogendra Jun 01 '18 at 12:31

1 Answers1

0

If you are using tagetSdk greater than 20 Use this edited Button

<Button android:id="@+id/btnRead"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/readmcq"
    android:text="@string/readmcq"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground"
    android:textAllCaps="false"
    android:textColor="@color/colorWhite"
    android:textSize="12sp" />  

if you are using lesser than use this

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground">

    <Button
        android:id="@+id/btnRead"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/readmcq"
        android:text="@string/readmcq"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textSize="12sp" />

</FrameLayout>

Let me know if it works. Happy coding :-)

Jitendra Singh
  • 130
  • 1
  • 16