0

i want to use custom buttons instead of normal buttons in android.

how can i customize button without using image.

custom button like this:

enter image description here

2

2 Answers 2

3

try below code:-

        <Button
            android:id="@+id/action"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:layout_margin="5dp"
            android:background="@drawable/btn_click"
            android:gravity="center"
            android:textColor="@color/white"
            android:textSize="12sp" />

btn_hover.xml

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

    <stroke
        android:width="1dp"
        android:color="#000000" />

    <gradient
        android:angle="270"
        android:centerColor="#1a000000"
        android:endColor="#33000000"
        android:startColor="@android:color/transparent" >
    </gradient>

    <corners android:radius="5dp" />

</shape>

btn.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke 
        android:color="#000000"
        android:width="1dp"
        />
    <gradient
        android:angle="270"
        android:centerColor="@android:color/transparent"
        android:endColor="@android:color/transparent"
        android:startColor="@android:color/transparent" >
    </gradient>
    <corners android:radius="5dp" />
</shape>

btn_click.xml

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

    <item android:drawable="@drawable/btn_hover" android:state_pressed="true"/>
    <item android:drawable="@drawable/btn"/>

</selector>
Sign up to request clarification or add additional context in comments.

Comments

0

you can create like this below image by programmatically. Ref Here:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.