0

I want to make a round button because originals buttons ("ToggleButton" class is the type of button I am using in my app) are a bit creepy and old fashioned. I am searching for a "xml" solution, and not simply change the image of the button because I want to keep the green or grey bar below the text of the button which is the basic display of a ToggleButton, just change the form of the button.

Can we do this ?

Anwar
  • 4,162
  • 4
  • 41
  • 62
  • possible duplicate of [custom circle Button](http://stackoverflow.com/questions/9884202/custom-circle-button) – Nathaniel D. Waggoner Jul 10 '14 at 17:51
  • I don't understand what you are asking. What do you mean by form? And of course you can style a `Button` anyway you want. – Xaver Kapeller Jul 10 '14 at 17:52
  • I would stylish my button by making it rounded and not rectangular. I searched for canvas but I am not sure this is the right solution. – Anwar Jul 10 '14 at 17:55
  • possible duplicate of [How to make the corners of a button round?](http://stackoverflow.com/questions/6054562/how-to-make-the-corners-of-a-button-round) – Lal Jul 10 '14 at 18:12
  • Yes it is sorry for that – Anwar Jul 10 '14 at 18:27

2 Answers2

0

i would create two xml drawables one for each state of the btn:(saved to your drawable folder)

rounded_btn_black.xml

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

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" 
    android:color="@color/black">
    <size
                android:height="100dp"
                android:width="10dp" />
    <corners
       android:radius="15dp"
         />



     <solid
        android:color="@color/black" />

</shape>

another one for orange just changing the color

and then create a selector xml file rounded_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/rounded_btn_black" android:state_pressed="true" />
    <item android:drawable="@drawable/rounded_btn_black" android:state_focused="true" />
    <item android:drawable="@drawable/rounded_btn_orange" android:state_enabled="true" />
    <item android:drawable="@drawable/rounded_btn_orange" />
</selector>

then in your layout:

<Button
        android:id="@+id/login"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/standard_btn_height"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="@dimen/standard_margin"
        android:layout_marginLeft="@dimen/standard_margin"
        android:layout_marginRight="@dimen/standard_margin"
        android:background="@drawable/rounded_button"
        android:text="@string/alreadyRegisterd"
        android:textColor="@color/white" >
    </Button>
erik
  • 4,946
  • 13
  • 70
  • 120
0

Find a way easier to make a button round :

Insted, I set to the android:shape the value oval.

Anwar
  • 4,162
  • 4
  • 41
  • 62