Reputation: 641
drawable-v21/ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent">
<item
android:drawable="@android:color/white"/>
</ripple>
TextView:
<TextView
android:id="@+id/tv_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center"
android:minWidth="200dp"
android:text="@string/back_to_school"
android:textColor="@color/color_sign_status"
android:textSize="16sp"/>
If I want to set RippleDrawable
to the TextView
, I must set android:background="?attr/selectableItemBackground"
, but how to set my custom background?
Or just to set background by the way:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:background="@drawable/bg_sign_tip"
android:gravity="center">
<TextView
android:id="@+id/tv_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center"
android:minWidth="200dp"
android:text="@string/back_to_school"
android:textColor="@color/color_sign_status"
android:textSize="16sp"/>
</LinearLayout>
If I use a Button
, this is the result:
This is terrible. Is there any other way?
Upvotes: 1
Views: 440
Reputation: 284
I think this can help you: You have to set your button's background to a RippleDrawable which you can define in XML. (I'll name it holo_blue_ripple.xml)
<item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->
Then reference it with android:background="@drawable/holo_blue_ripple"
Upvotes: 1