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
    • 156
    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

    1. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    2. <item android:state_pressed="true" >
    3. <shape android:shape="rectangle" >
    4. <corners android:radius="90dip" />
    5. <stroke android:width="1dip" android:color="#5e7974" />
    6. <gradient android:angle="-90" android:startColor="#345953" android:endColor="#00ff55" />
    7. </shape>
    8. </item>
    9. <item android:state_focused="true">
    10. <shape android:shape="rectangle" >
    11. <corners android:radius="3dip" />
    12. <stroke android:width="1dip" android:color="#5e7974" />
    13. <solid android:color="#58857e"/>
    14. </shape>
    15. </item>
    16. <item >
    17. <shape android:shape="rectangle" >
    18. <corners android:radius="90dip" />
    19. <stroke android:width="2dip" android:color="#5e7974" />
    20. <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#00ff55" />
    21. </shape>
    22. </item>
    23. </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

    1. <LinearLayout
    2. android:layout_marginTop="20dp"
    3. android:layout_marginLeft="20dp"
    4. android:layout_marginBottom="20dp"
    5. android:layout_marginRight="20dp"
    6. android:background="#ccffdd"
    7. android:layout_width="match_parent"
    8. android:layout_height="match_parent"
    9. android:orientation="vertical">
    10. <EditText
    11. android:id="@+id/email_et"
    12. android:layout_marginRight="20dp"
    13. android:layout_width="match_parent"
    14. android:hint="email"
    15. android:singleLine="true"
    16. android:layout_height="wrap_content" />
    17. <EditText
    18. android:singleLine="true"
    19. android:id="@+id/user_name_et"
    20. android:layout_marginTop="20dp"
    21. android:layout_marginRight="20dp"
    22. android:hint="User Name"
    23. android:layout_width="match_parent"
    24. android:layout_height="wrap_content" />
    25. <EditText
    26. android:singleLine="true"
    27. android:id="@+id/dob_et"
    28. android:layout_marginTop="20dp"
    29. android:layout_marginRight="20dp"
    30. android:focusable="false"
    31. android:hint="Date of birth"
    32. android:inputType="date"
    33. android:layout_width="match_parent"
    34. android:layout_height="wrap_content" />
    35. <EditText
    36. android:singleLine="true"
    37. android:id="@+id/mobile_no_et"
    38. android:layout_marginTop="20dp"
    39. android:layout_marginRight="20dp"
    40. android:hint="Phone Number"
    41. android:inputType="number"
    42. android:maxLength="10"
    43. android:layout_width="match_parent"
    44. android:layout_height="wrap_content" />
    45.  
    46.  
    47. <Button
    48. android:layout_marginTop="50dp"
    49. android:id="@+id/sign_up_btn"
    50. android:layout_width="150dp"
    51. android:layout_height="wrap_content"
    52. android:background="@drawable/custom_button"
    53. android:text="@string/sign_up"
    54. android:textSize="25dp"
    55. android:layout_gravity="center"/>
    56. </LinearLayout>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: