AS 4.0.1
Use app:drawableEndCompat instead of android:drawableEnd
warning on API 21 and above
<TextView
android:id="@+id/tvCheckStock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_pin_drop
android:gravity="center_vertical"/>
The ic_pin_drop is a SVG (Vector Drawable) that was created using Android Studio File | New | Vector Asset | Configure Vector Assert
In my Build.gradle
file I have the following configuration:
minSdkVersion 21
targetSdkVersion 29
vectorDrawables.useSupportLibrary true
As the min is API 21 which is Lollipop I was thinking that vector drawables are supported out of the box and we can use the DrawableEnd, DrawableStart etc without the compat versions?
I was thinking that the compat versions were for pre 21 API level. Kitkat and below. And as I am not targeting that minimum I am not sure why I am getting that warning.
This would result in a cash on those devices less than 21 if the compat version is not used.
Many thanks for any suggestions.
The primary motive behind this warning is to make your VectorDrawables look same on all devices by making them backward compatible.
By using "Compat", you would be ensuring that using your vector asset would not crash your app for devices below API 21(Lollipop). In short, using drawableEndCompat
would allow anyone to use the same features of drawableEnd
on older APIs(<21).
Now you would be thinking that what should I choose:
If you are using drawableEndCompat
, it would work as you expect in every device. Devices with API more than 21 would internally unwrap them as normal drawableEnd
as far as I know.
If you choose to use drawableEnd
, it will be working for API 21 and above only.
If you think that I don't need any Compat Support : You may increase your application's minimum SDK from current value to atleast 21. Then you can use keyword drawableEnd
peacefully without any warning.
Also, you may opt to create different layout file for different APIs under which in layout file for below API 21, use drawableEndCompat
and for API 21 and above use drawableEnd
. In my opinion, you can also check whether you can use both attributes at same place. I feel like that they can work together as well.
If you are not supporting devices below API 21, there is no problem: You should have no issues/warning. Also, one more thing I need to tell you - Android Studio sometimes throw warnings or bugs; even if you are right. In that case, if you feel that you were correct, you should try invalidate/restart option after clicking File option in Menu Bar. I would also suggest to try restarting your system to everyone who are using system for long durations or always keeping it on sleep mode.
So, for a TextView
, you should use app:drawableEndCompat
(or start, top, bottom) instead of app:drawableEnd