Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompatButton backgroundTint API < 21

I want to use ripple effects on Buttons. AppCompat v22.1 added AppCompatButton and new functionalities to AppCompat tinting.

My Layout:

<android.support.v7.widget.AppCompatButton         android:id="@+id/add_remove_button"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:backgroundTint="@color/primary"         android:textColor="@android:color/white"         android:text="Remove" /> 

On my API 22 test device the ripple effect works perfectly, but i'm coding for API 11 and unfortunately backgroundTint needs API >= 21. How can i set the ripple effect to Buttons on older API versions?

like image 216
Thomas Mohr Avatar asked Apr 27 '15 08:04

Thomas Mohr


2 Answers

Just use app:backgroundTint instead of android:backgroundTint, the tint will take effect below Lollipop. The reason is AppCompatActivity AppCompatDelegateImplV7 use AppCompatViewInflater to auto change Button or TextView to AppCompatButton or AppCompatTextView, then app:backgroundTint take effect.

enter image description here

like image 145
drakeet Avatar answered Sep 22 '22 13:09

drakeet


Ripples are not available as a build in functionality on Android <21. This is due to performance issues: devices with the new API can use the RenderThread which is not available to older devices. See also: http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html

Why are there no ripples on pre-Lollipop? A lot of what allows RippleDrawable to run smoothly is Android 5.0’s new RenderThread. To optimize for performance on previous versions of Android, we've left RippleDrawable out for now.

like image 29
and_dev Avatar answered Sep 24 '22 13:09

and_dev