Drawable tinting for api 21
Use the AppCompatImageView
like so:
<android.support.v7.widget.AppCompatImageView
android:id="@+id/my_appcompat_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"
android:tint="#636363"
/>
Make sure you have the latest appcompat-v7
in your app's build.gradle
.
Example: compile 'com.android.support:appcompat-v7:25.0.0'
in your app's build.gradle
.
How to apply backgroundTint to a ViewGroup for API 21?
I'm not quite sure what the problem is, but I've found a workaround which works for API 21.
view.getBackground().setColorFilter(tint_color, PorterDuff.Mode.SRC_OVER);
has the same effect as
view.setBackgroundTintList(ColorStateList.valueOf(tint_color));
How to change drawable tint of a button below api level 23 programmatically in android
you are using PorterDuff.Mode.MULTIPLY
, so you are multiplying colors. assuming (name of your drawable) your icon is black - #000000
or as int
it will be 0
. then 0 * GRAY
(or any other color) will always give you 0
, so still black...
try other PorterDuff.Mode
s, e.g. PorterDuff.Mode.SRC_ATOP
or PorterDuff.Mode.SRC_IN
your current code will probably work with white version of icon, which should be colored properly with MULTIPLY
How change icons color on API 21?
I'm not sure what APIs you exactly mean by saying "backgroundTint and ImageTint", but there's a compatibility ViewCompat
class which will backport some functionality up to API 4.
Amongst them are:
setBackgroundTintList(View, ColorStateList)
setBackgroundTintMode(View, ColorStateList)
If by saying "ImageTint" you meant android:tint
or setImageTintList()
, then this answers your question.
Custom RatingBar tinting API 21 with support library 22.1.1
With support library > 22 I managed to do this using getProgressDrawable
LayerDrawable stars = (LayerDrawable) bar.getProgressDrawable();
stars.getDrawable(0).setColorFilter(NONE_COLOR, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(1).setColorFilter(FULL_COLOR, PorterDuff.Mode.SRC_ATOP);
stars.getDrawable(2).setColorFilter(PARTIAL_COLOR, PorterDuff.Mode.SRC_ATOP);
This didn't work before support library 22 so I think this will solve your problem.
Android TextView DrawableTint on pre v23 devices
AndroidX appcompat library supports tinting in TextView since version 1.1.0-alpha03 [ref].
Add dependencies to appcompat library
dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
}
Then drawable in TextView can be tinted from XML like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:drawableStartCompat="@drawable/ic_plus"
app:drawableTint="@color/red" />
Don't forget to include
xmlns:app="http://schemas.android.com/apk/res-auto"
and to extend your Activity from AppCompatActivity
.
Related Topics
No Network Security Config Specified, Using Platform Default - Android Log
How to Change the Color of the Tabs Indicator Text in Android
How to Change Color of Listview Items on Focus and on Click
Proguard Missing Type Parameter
Android Studio Build Fails with "Task '' Not Found in Root Project 'Myproject'."
Fragment Replacing in Recyclerview Item
Failed to Resolve: Com.Github.Philjay:Mpandroidchart:V2.1.4
How to Make My Own Custom Dialer in an Android Phone
How to Use Intent for Choosing File Browser to Select File
How to Authenticate Two Types of Users (Student and Driver) in My Android App Using Firebase
Android Beginner Difference Between Padding and Margin
Convert Xml to JSON Object in Android
Android Emulator Won't Run Application Started from Eclipse
Generating Google Map Release API Key
Onclicklistener - X,Y Location of Event
Activate an Application When a Power Button Is Clicked
Check If User Is Authenticated for the First Time in Firebase Google Authentication in Android