سؤال

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

هل كانت مفيدة؟

المحلول

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>

نصائح أخرى

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

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top