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_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp"
android:text="Button"
android:background="@drawable/buttonshape"/>
</RelativeLayout>
0 Comment(s)