1

I'm trying to apply tint for ImageButton that uses vector drawable:

<android.support.v7.widget.AppCompatImageButton
           android:id="@+id/flashlight_button"
           app:srcCompat="@drawable/ic_flash_off_black_24dp"
           android:tint="@color/icon_states_color"
           />

This will work Lollipop +, but will crash on Kitkat.

How should do ColorList tint for Kitkat in app compat world?

Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197

2 Answers2

0

hi you can programmatically add tint in your image button and make check if it below lollipop then it work below aternate way.

According to the documentation the related method to android:backgroundTint is setBackgroundTintList(ColorStateList list)

Update

Follow this link to know how create a Color State List Resource.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:color="#your_color_here" />
</selector>

then load it using

setBackgroundTintList(contextInstance.getResources().getColorStateList(R.color.your_xml_name));

where contextInstance is an instance of a Context


using AppCompart

btnTag.setSupportButtonTintList(ContextCompat.getColorStateList(Activity.this, R.color.colorPrimary));

Try this way, hope this will help you.

Saveen
  • 4,120
  • 14
  • 38
  • 41
0

android:tint within vector drawable with work. So just android:tint in layout should be avoided.

Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197