-1

Vector drawable of image contains Gradient colors, which are not showing in imageview for below API version of 24, i am using Android-Studio 3.1

color.xml:

   <?xml version="1.0" encoding="utf-8"?>
<gradient xmlns:android="http://schemas.android.com/apk/res/android"
android:centerX="143.856"
android:centerY="64.935"
android:gradientRadius="220.29005"
android:type="radial">
<item
    android:color="#FFFFFFFF"
    android:offset="0" />
<item
    android:color="#FFEFEFEF"
    android:offset="0.412" />
<item
    android:color="#FFC7C9CA"
    android:offset="0.813" />
<item
    android:color="#FFBDBFC1"
    android:offset="1" />
</gradient>

ic_card.xml

 <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="288dp"
android:height="130dp"
android:autoMirrored="true"
android:viewportWidth="288"
android:viewportHeight="130">
<path
    android:fillColor="@color/tohumkart1"
    android:pathData="M0,0H288V130H0Z"></path>
<path
</vector>

build.gradle:

vectorDrawables.useSupportLibrary = true

Application.java :

   static
{
   AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

implementaion:

 val cardImage = creditCardModel?.let { cardHelper.getCardImage(it) }
                 cardImage?.let { brCardImage.setImageResource(it) }

tried:

cardHelper.getDrawable(ApplicationContext.getInstance().activityContext,cardImage!!)

Is there any way to reflect gradient colors in imageview under API 23 with Android Studio 3.0.?

Muhamed El-Banna
  • 593
  • 7
  • 21
mervegenc
  • 13
  • 5

1 Answers1

-1

i tried on API 21 and it's working !

am working in java not kotlin ,, and i used the drawable resource in xml not in code

and i didn't use this part

AppCompatDelegate.setCompatVectorFromResourcesEnabled()

and as mentioned in this answer you have to use setImageDrawable not setImageResource

enter image description here

Muhamed El-Banna
  • 593
  • 7
  • 21
  • android.content.res.Resources$NotFoundException: File res/drawable/ic_saleplusgoldkart.xml from drawable resource ID #0x7f02024e. If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info. at android.content.res.Resources.loadDrawable(Resources.java:1923) – mervegenc Mar 30 '20 at 11:55
  • What is your grade version? My grade version is 2.3.3 – mervegenc Mar 30 '20 at 12:51
  • distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip – Muhamed El-Banna Mar 30 '20 at 13:06