Custom Button in Android

Simple Custom Button Example in Android

MainCLASS

package com.example.malik.test;

import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
}

 

MainXML

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout 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:orientation=”vertical”
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=”com.example.malik.test.MainActivity”>
<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”New Button”
android:id=”@+id/button”
android:layout_gravity=”center_horizontal” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”New Button”
android:id=”@+id/button2″
android:layout_marginTop=”25dp”
android:layout_gravity=”center_horizontal” />

<Button
android:layout_width=”125dp”
android:layout_height=”80dp”
android:text=””
android:background=”@drawable/custom”
android:id=”@+id/button23″
android:layout_marginTop=”25dp”
android:layout_gravity=”center_horizontal” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”New Button”
android:id=”@+id/button22″
android:layout_marginTop=”25dp”
android:layout_gravity=”center_horizontal” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”New Button”
android:id=”@+id/button21″
android:layout_marginTop=”25dp”
android:layout_gravity=”center_horizontal” />
</LinearLayout>

 

Custom XML

<?xml version=”1.0″ encoding=”utf-8″?>
<selector xmlns:android=”http://schemas.android.com/apk/res/android”>

<item android:state_pressed=”true” android:drawable=”@drawable/pic1″></item>
<item android:state_focused=”true” android:drawable=”@drawable/pic4″></item>
<item android:drawable=”@drawable/pic3″></item>
</selector>

 

Output :

pic

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.