sama sama - 1 month ago 10
Android Question

How to create custom Button?

I want to create a custom Button in my app, like the image below:
enter image description here

This is a Button from an app where when I press it, another Activity starts.

How can I create a Button like this?

I'll appreciate any help.

Editted:

button_back.xml :

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

<gradient
android:angle="90"
android:startColor="#4080FE"
android:centerColor="#4080FE"
android:endColor="#4080FE"
android:type="linear" />

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



<size
android:width="40dp"
android:height="40dp"
/>




and in layout :

<Button
android:layout_width="wrap_content"
android:layout_height="80dp"
android:drawableLeft="@drawable/btn"
android:background="@drawable/button_back"

android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="94dp" />


and this is the output:
enter image description here

I don't want those red circles to be shown; I want my button be the same as first picture without any boredr.

Thank you for your helping.

Last Edition:

I used imageButton instead of button and it is correct solution for my case.

Answer

Try this way to get the shape for your view

create go_btn.xml

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

    <gradient
        android:angle="90"
        android:startColor="#4080FE"
        android:centerColor="#4080FE"
        android:endColor="#4080FE"
        android:type="linear" />

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



    <size
        android:width="40dp"
        android:height="40dp"
        />


</shape>

and then add it to your layout

<ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:padding="10dp"
        android:src="@drawable/autoorder"
        android:background="@drawable/go_btn"
        android:layout_gravity="center"
android:layout_marginTop="10dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Calender"
        android:layout_gravity="center"
        />

OUTPUT

enter image description here