fatih
fatih

Reputation: 1420

How do I create a gradient for Android Api Level 19 and later?

I'm trying to add colors to the toolbar for a project. There are different toolbar colors for each. I am trying to create a new project in my project. I am using a new project. But I do have a big deal. The Svg's have the gradient. I can use these for post api 24 without problems. But I can't use the same svgs because they don't support gradient under api 24. I don't know how to figure this out except to undo gradients. That's why I'm sharing one of my Svg's downstairs.

My ic_sale_toolbar.xml ;

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="375dp"
    android:height="90dp"
    android:viewportWidth="375"
    android:viewportHeight="90">
  <path
      android:pathData="M0,0h375v90h-375z"
      android:strokeWidth="1"
      android:fillType="evenOdd"
      android:strokeColor="#00000000">
    <aapt:attr name="android:fillColor">
      <gradient 
          android:startY="186.48047"
          android:startX="357.47266"
          android:endY="-171.41406"
          android:endX="66.76172"
          android:type="linear">
        <item android:offset="0" android:color="#FF3023AE"/>
        <item android:offset="1" android:color="#FFC86DD7"/>
      </gradient>
    </aapt:attr>
  </path>
</vector>

Upvotes: 1

Views: 603

Answers (1)

Manoj Kumar
Manoj Kumar

Reputation: 11

Try this
`<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient android:endColor="@color/colorPrimary" android:startColor="@color/colorPrimaryDark"
                android:centerColor="@color/colorPrimary" android:angle="315"
                android:gradientRadius="2dp"/>
            <padding android:left="2dp" android:top="3dp" android:right="2dp"
                android:bottom="3dp"/>
        </shape>
    </item>
</selector>`

Upvotes: 1

Related Questions