I am making an android app with a few fragments. In one of these fragments, I have a toolbar with a back arrow as an image button.
In the XML File, I have the "app:srcCompat" attribute, but I get an error when using this attribute saying this: "To use VectorDrawableCompat, you need to set 'android.defaultConfig.vectorDrawables.useSupportLibrary = true'
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.
In Android 5.0 (API Level 21) and above, you can define vector drawables, which scale without losing definition. Changing the width and height in the definition of the vector drawable to 200dp significantly improves the situation at the 400dp rendered size.
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.
Also, you need to add this block of code in every activity or fragment where you're referencing drawables instead of images in srcCompat: Show activity on this post. You have to add vectorDrawables.useSupportLibrary = true this line of code in you app level build.gradle inside the defaultConfig tag
For example, using VectorDrawableCompat from AndroidX enables: Both nonZero and evenOdd path fillTypes —the two common ways of defining the inside of a shape, often used in SVGs ( evenOdd added to platform impl in API 24) Gradient & ColorStateList fills/strokes (added to platform impl in API 24)
VectorDrawableCompat can be defined in an XML file with the <vector> element. The VectorDrawableCompat has the following elements: <vector> Used to define a vector drawable android:name Defines the name of this vector drawable. android:width Used to define the intrinsic width of the drawable. This support all the dimension units, normally ...
In your module build.gradle
file, you need to add this line:
apply plugin: 'com.android.application' android { ... defaultConfig { ... vectorDrawables.useSupportLibrary = true // This line here } ... } ...
add this line to your Gradle file under defaultConfig
block:
vectorDrawables.useSupportLibrary = true
Also, you need to add this block of code in every activity or fragment where you're referencing drawables instead of images in srcCompat
:
static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }
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