I am trying to use
android:background="?android:attr/selectableItemBackground"
to get my button to do appropriate effects for each android version like rippling, etc.
But this produces a button with a grey color when I need a different color.
How can I override this default color ?
If you read the source code of Button.java then you will see that it is a subclass of TextView.java. I have made a simple workaround for the problem in question.
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:background="#1f5050"> <TextView android:layout_width="some_dp" android:layout_height="some_dp" android:id="@+id/button" android:background="?android:selectableItemBackground" /> </LinearLayout>
In code:
button.setOnClickLisetener(new Onclicklistener() { // do your stuff here }
It would be much better if someone can extend the TextView class and make a custom Button with the feature in question.
Note: my minsdk is 14. also, the lollipop ripple effect works just fine
Just move your desired color in outer/parent level, e.g. "@color/Red" is button color:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/Red" android:layout_weight="1"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/selectableItemBackground" android:gravity="center" android:text="Hello" android:textColor="@color/White"/> </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