1

How to get this view of button with gradient background?

I googled a lot but hadn't find something

and I think overlapping of one on other is because of relative layout..

enter image description here

Parth Sharma
  • 359
  • 1
  • 4
  • 21
  • See the similar questions answer: http://stackoverflow.com/questions/19797430/android-complex-shape-button/19801248#19801248. If you haven't done this before let me know and I will try to post an answer that more specifically targets your question. – RocketSpock Nov 27 '13 at 19:19

1 Answers1

6

Create a xml file in drawable folder:

oval_background.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" >
    <gradient 
        android:startColor="#6586F0"
        android:centerColor="#D6D6D6"
        android:endColor="#4B6CD6"
        android:angle="90"/>

</shape>  

Use this file as button background:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/oval_background"
    android:id="@+id/ButtonTest"
    android:text="button">
</Button>
ramaral
  • 6,149
  • 4
  • 34
  • 57
  • Is there a way to make it look circular? – Ruchir Baronia Jan 23 '16 at 07:41
  • @RuchirBaronia An oval shape fits the dimensions of the containing View, then to have a circle the width and height of the view should be the same. You can also use the ` element of `` to define the dimensions. See the documentation for [Shape](http://developer.android.com/intl/pt-br/guide/topics/resources/drawable-resource.html#Shape) – ramaral Jan 23 '16 at 11:33