Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create a Custom Button

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 387
    Comment on it

    How to create Custom Button in Android

    In Android it is very easy to use buttons , eclipse Ide provides you with drag and drop functionality.But we can use different approach and create our own custom button.

    create an android project, in its xml layout file make a button . then create a xml file in @drawlble/buttonshape .Put the following code in it

    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android">
        <stroke 
            android:width="1dp" 
            android:color="#505050"/>
        <corners 
            android:radius="10dp" />
    
        <padding 
            android:left="2dp"
            android:right="2dp"
            android:top="2dp"
            android:bottom="2dp"/>
    
        <solid android:color="#505050"/>
    
    </shape>
    

    Then add following code to the button in xml file in android:background="@drawable/buttonshape

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout&#95;width="match&#95;parent"
        android:layout&#95;height="match&#95;parent"
        android:paddingBottom="@dimen/activity&#95;vertical&#95;margin"
        android:paddingLeft="@dimen/activity&#95;horizontal&#95;margin"
        android:paddingRight="@dimen/activity&#95;horizontal&#95;margin"
        android:paddingTop="@dimen/activity&#95;vertical&#95;margin"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/button1"
            android:layout&#95;width="wrap&#95;content"
            android:layout&#95;height="wrap&#95;content"
            android:layout&#95;centerHorizontal="true"
            android:layout&#95;marginTop="43dp"
            android:text="Button" 
            android:background="@drawable/buttonshape"/>
    
    </RelativeLayout>
    

 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: