3

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Anna
  • 39
  • 1
  • 3
  • 2
    Possible duplicate of [Drawable tinting for api <21](https://stackoverflow.com/questions/29155463/drawable-tinting-for-api-21) – Dima Kozhevin Oct 07 '17 at 19:42
  • yes i saw that answers but could you please help me understanding this step by step? can i handle this by the xml file only without help of .java file? – Anna Oct 07 '17 at 19:44
  • @DimaKozhevin This is about tinting *compound drawables in a TextView*. This has nothing to do with image drawable tinting. – Eugen Pechanec Oct 07 '17 at 23:23
  • @EugenPechanec my mistake. It is possible to duplicate of https://stackoverflow.com/questions/30938620/android-button-drawable-tint This one should be closed I check comment of https://stackoverflow.com/users/1025193/boris in https://stackoverflow.com/a/30946356/3166697 Problem can be resolved couple line code: `AppCompatButton b = findViewById(R.id.button_not_working); Drawable[] drawables = b.getCompoundDrawables(); Drawable wrapDrawable = DrawableCompat.wrap(drawables[2]); DrawableCompat.setTint(wrapDrawable, getResources().getColor(android.R.color.white));` – Dima Kozhevin Oct 08 '17 at 00:21

2 Answers2

2

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'
}
Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
-4

You have to use the tint atttibute

EDIT: My mistake, it should be backgroundTint

Antonio Vlasic
  • 337
  • 3
  • 15
  • `tint` is used for foreground image of ImageView and ImageButton. `backgroundTint` is used for background. `drawableTint` is for compound drawables of a TextView or Button. Also, there's a difference between `app:tint` and `android:tint` (same for other attributes). `app:tint` works as expected since support library 25.4.0. – Eugen Pechanec Oct 07 '17 at 23:26