1

I am trying to make an XML Button, circle shape, which is filled with a gradient color. This color needs to be changed programatically.

Here is an example of what I am trying to achieve.

enter image description here

My attempts to build this have ended up with a gradient background and a solid colored circle. Instead of the gradient circle and transparent background.

I am hoping to be able to use more then 2 colors or a radial gradient for the circle as well. Any help is greatly appreciated.

Travis Knight
  • 271
  • 1
  • 3
  • 15

2 Answers2

1

You can Try with making Drawable XML. Example

    <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="circle" >

    <gradient
        android:angle="90"
        android:centerColor="#555994"
        android:endColor="#b5b6d2"
        android:startColor="#555994"
        android:type="linear" />    

</shape>

Arrange angle based on your requirement.

If you wants to change Color progarmatically then read this:-

How do I programmatically set the background color gradient on a Custom Title Bar?

Community
  • 1
  • 1
Hradesh Kumar
  • 1,593
  • 13
  • 18
0

Belated but can be helpful for someone else

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <gradient android:angle="0" android:endColor="#fff" android:gradientRadius="@dimen/_30sdp" android:startColor="@color/colorPrimaryDark" android:type="radial" />
        <size android:width="@dimen/_25sdp" android:height="@dimen/_25sdp" />
    </shape>
</item>

Output enter image description here