I have a textView with drawableTop, but the image is in black color and i would like to change the color to white.Is there a way to do it without creating seperate imageView and TextView.
Below is the xml for reference.
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center_horizontal|bottom"
android:drawableTop="@drawable/ic_add_room"
android:text="More"/>
Use Tint android:drawableTint to change color. Exmp :
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:drawableTint="#fff"
android:layout_height="48dp"
android:gravity="center_horizontal|bottom"
android:drawableTop="@drawable/ic_add_room"
android:text="More"/>
Solution 1 - @drawable/ic_add_room
if this is xml file then go to ic_add_room.xml inside drawable folder.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M13,7h-2v4L7,11v2h4v4h2v-4h4v-2h-4L13,7zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
modify fillColor as your requirement...
Example-
android:fillColor="#FFE25959"
Solution 2 - for change color dynamic
Drawable drawable = getResources().getDrawable(R.drawable.circle);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.GREEN);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
textview.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With