Android - support for vector drawings on Motorolla

I have a problem with a rendering vector that can be carried on Motorola phones to Lollipop. I tested it on moto g and others with KitKat. Every time I launch the application, some icons look damaged, and some are missing at all. And after each launch, they are corrupted in a different way. On Lenovo, Samsung, ASOP Emulator and others from JB + to Nougat, everything is fine. Only Motorolla phones cannot provide vector rendering using the support library. Does anyone have the same problem?

+5
source share
5 answers

Vector Drawables are also supported in cases such as the TextView drawableLeft property. follow this link Android Studio 1.4

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/icon" 
+2
source

Try adding the following to the onCreate () method of your Application class:

 AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); 

From official docs:

When enabled, AppCompat can capture some profitable inflation from the framework, which allows implicit inflation of vector resources in DrawableContainer resources.
You can then use these drawings in places like android: src on ImageView, or android: drawableLeft in TextView.
This feature is disabled by default because enabling it can cause memory problems and problems updating configuration instances.
If you update the configuration manually, you probably won't want to enable this. You have been warned.

+2
source

In my research, I found two ways to support vector drawing on preinstalled devices. You can try this.

You can support all vector wrapping devices with AppCompatImageView

 <android.support.v7.widget.AppCompatImageView app:srcCompat="" // your drawable declaration android:layout_width="wrap_content" android:layout_height="wrap_content"/> 

android.support.v7.appcompat: srcCompat

Sets a valid value as the contents of this ImageView. Allows you to use the vector you can use when working on older versions of the platform.

Requires library support 23.4.0 or later

Source: https://developer.android.com/reference/android/support/v7/widget/AppCompatImageView.html#attr_android.support.v7.appcompat:srcCompat

Another way is to configure the vector setting in Gradle. Add the code below to Gradle.

 android { defaultConfig { vectorDrawables.useSupportLibrary = true } } 

Using srcCompat in ImageView

 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_add" /> 

Source: https://android-developers.googleblog.com/2016/02/android-support-library-232.html

Hope this helps you :)

+1
source

If you want to use a vector with ImageView, you must use srcCompat -AppCompatImageView. However, if you want to use a vector with drawableLeft .. use this library https://github.com/bsobe/vectorview

0
source

Try it: -

 Drawable date = AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_date_range_black_24dp); etDeliveryDate.setCompoundDrawablesWithIntrinsicBounds(date, null, null, null); 
0
source

Source: https://habr.com/ru/post/1270738/


All Articles