Gurjeet Singh
Gurjeet Singh

Reputation: 697

Round corners of buttons and colour change for android button

I want to following features in buttons in android button:

  1. Buttons should change colours when clicked

  2. Some specific buttons have features like the background color of button should remain changed until we press another button.

Upvotes: 5

Views: 1104

Answers (2)

Pankaj Lilan
Pankaj Lilan

Reputation: 4453

For circular and for changing color when selected/not-selected button you can use following code snippet

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <shape android:shape="oval">
            <solid android:color="@color/colorPrimary"/>
        </shape>
    </item>
    <item android:state_pressed="true">
        <shape android:shape="oval">
            <solid android:color="@color/colorPrimaryDark"/>
        </shape>
    </item>
</selector>

And you problem will be solved, hope it helps.

Upvotes: 1

devangi chhatbar
devangi chhatbar

Reputation: 91

For rounded corners you can use below code :

 @drawable/rounderd_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />

<stroke
    android:width="1dp"
    android:color="@color/YOUR_COLOR" />

<corners
    android:bottomLeftRadius="8dp"
    android:bottomRightRadius="8dp"
    android:topLeftRadius="8dp"
    android:topRightRadius="8dp" />

And For selector Buttons use below @drawable/select_button_color.xml

   <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/YOUR_COLOR" />

<corners
    android:bottomLeftRadius="8dp"
    android:bottomRightRadius="8dp"
    android:topLeftRadius="8dp"
    android:topRightRadius="8dp" />

And Change background resource when button is clicked

Upvotes: 1

Related Questions