Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make custom button in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 128
    Comment on it

    To make Custom Button in android follow the steps mentioned below:-

    1) Create a drawable resource file in your drawable folder and name it custom_button.xml.

    2) Add the code written below in your custom_button.xml file .

     custom_button.xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true" >
            <shape android:shape="rectangle"  >
                <corners android:radius="90dip" />
                <stroke android:width="1dip" android:color="#5e7974" />
                <gradient android:angle="-90" android:startColor="#345953" android:endColor="#00ff55"  />
            </shape>
        </item>
        <item android:state_focused="true">
            <shape android:shape="rectangle"  >
                <corners android:radius="3dip" />
                <stroke android:width="1dip" android:color="#5e7974" />
                <solid android:color="#58857e"/>
            </shape>
        </item>
        <item >
            <shape android:shape="rectangle"  >
                <corners android:radius="90dip" />
                <stroke android:width="2dip" android:color="#5e7974" />
                <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#00ff55" />
            </shape>
        </item>
    </selector>

     

    In the above code <stroke> tag is being used for outlining effect of the button and <gradint> tag is being used for shading effect in button.

     

    3) Now call this file in the <button> tag's background property in your activity_main.xml.

    activity_main.xml

    <LinearLayout
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginBottom="20dp"
            android:layout_marginRight="20dp"
            android:background="#ccffdd"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
     <EditText
                android:id="@+id/email_et"
                    android:layout_marginRight="20dp"
                    android:layout_width="match_parent"
                    android:hint="email"
                android:singleLine="true"
                    android:layout_height="wrap_content" />
            <EditText
                android:singleLine="true"
                android:id="@+id/user_name_et"
                android:layout_marginTop="20dp"
                    android:layout_marginRight="20dp"
                    android:hint="User Name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            <EditText
                android:singleLine="true"
                android:id="@+id/dob_et"
                android:layout_marginTop="20dp"
                android:layout_marginRight="20dp"
                android:focusable="false"
                android:hint="Date of birth"
                android:inputType="date"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <EditText
                android:singleLine="true"
                android:id="@+id/mobile_no_et"
                android:layout_marginTop="20dp"
                android:layout_marginRight="20dp"
                android:hint="Phone Number"
                android:inputType="number"
                android:maxLength="10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
    
            <Button
                android:layout_marginTop="50dp"
                android:id="@+id/sign_up_btn"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:background="@drawable/custom_button"
                android:text="@string/sign_up"
                android:textSize="25dp"
                android:layout_gravity="center"/>
            </LinearLayout> 

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: