Reputation: 21
I want to add gradient function on stroke(button and textview), but I don't know how to code it.
Upvotes: 0
Views: 246
Reputation: 173
<?xml version="1.0" encoding="utf-8"?>
<stroke android:color="@color/blue"
android:width="1dp">
<gradient
android:type="linear"
android:angle="270"
android:endColor="#4e5eff"
android:startColor="#2686ff" />
</stroke>
<corners android:radius="30dp"/>
Upvotes: 0
Reputation: 58
Go to res --> drawable (right click) --> New ---> Drawable resource file. Name your file name anything you like and click OK. When the resource file layout opens, you can copy and paste the codes below:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<item android:state_pressed="true">
<shape>
<solid
android:color="#EF4444"/>
<stroke
android:width="2dp"
android:color="#000000"/>
<corners
android:radius="3dp"/>
<padding
android:left="10dp"
android:right="10dp"
android:top="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#1B34D8"
android:endColor="#D8A91B"
android:angle="270"/>
<stroke
android:width="1dp"
android:color="#008577"/>
<corners
android:radius="3dp"/>
<padding
android:left="10dp"
android:right="10dp"
android:top="10dp"
android:bottom="10dp"/>
</shape>
</item>
</selector>
Then add the codes below to your Button or TextView.
android: background="@drawable/your_resource_file_name"
Upvotes: 1
Reputation: 692
here an example for you that may help.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="360"
android:centerColor="#e95c12"
android:endColor="#ff00b4"
android:gradientRadius="360"
android:startColor="#006342"
android:type="sweep" />
<stroke
android:width="2dp"
android:color="#ff217a00" />
</shape>
</item>
<item
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp">
<shape android:shape="rectangle" >
<solid android:color="#fff" />
</shape>
</item>
</layer-list>
Upvotes: 2