AppCompatButton backgroundTint API < 21

Thomas Mohr picture Thomas Mohr · Apr 27, 2015 · Viewed 25.7k times · Source

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?

Answer

drakeet picture drakeet · Jul 13, 2016

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