drawableTint is not working through used AppCompact-v7:25.3.1

Viewed 3361

This question is already exist in here. But I want to know this step by step. I pasted the dependence in gradle under dependencies.

compile 'com.android.support:appcompat-v7:25.3.1'

and than what to do. My xml code is here

<Button
    android:id="@+id/button_not_working"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageViewGroup"
    android:layout_marginTop="60dp"
    android:paddingEnd="9dp"
    android:layout_alignStart="@+id/imageViewGroup"
    android:layout_alignEnd="@+id/imageViewGroup"
    android:background="@drawable/button_background"
    android:text="Drawable Tine not working"
    android:textColor="@color/white"
    android:textSize="@dimen/font_size_small"
    android:textAlignment="center"
    android:layout_marginBottom="10dp"
    android:drawableEnd="@drawable/forword_arrow"
    android:drawableTint="@color/white"
    android:gravity="center"
    />

this is the picture

enter image description here

The color of the forward_arrow is not changing. There are several answer in here but want to know what to do step by step. That's it.

2 Answers

Tinting compound drawables in TextView (and their descendants such as Button) was introduced in API 23 (Android 6) via android:drawableTint and android:drawableTintMode attributes.

As of today this feature was not yet backported to AppCompat support library.


Naturally I took an attempt at solving this myself. Check out the appcompat-extra library. It has the XpAppCompatTextView and XpAppCompatButton widgets. Your code may look like this:

<android.support.v7.widget.XpAppCompatButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Drawable tint working"
    android:drawablePadding="8dp"
    app:drawableEnd="@drawable/forword_arrow"
    app:drawableTint="?android:textColorPrimary"/>

Note that android:drawablePadding still uses the android prefix.

Layout preview of this widget may be broken. In such case add the following code so you at least know what the result app will look like:

    tools:drawableEnd="@drawable/forword_arrow"
    tools:drawableTint="?android:textColorPrimary"

To get the library put this in your app module build.gradle:

repositories {
    maven { url 'https://dl.bintray.com/consp1racy/maven/' }
}

dependencies {    
    compile 'net.xpece.android:appcompat-extra:1.2.0'
}

You have to use the tint atttibute

EDIT: My mistake, it should be backgroundTint

Related