Archive

Archive for November, 2010

Customize button in Android

November 9, 2010 32 comments


hi!!
You can change the appearance of button in android like make the corners of button rounded etc…

button_shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape      xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
    
    <solid   android:color="#EAEAEA"/>
    
    <corners    android:bottomLeftRadius="8dip"
                android:topRightRadius="8dip"
                android:topLeftRadius="1dip"
                android:bottomRightRadius="1dip"
                />
</shape>

here you can change the radius of corners

you can use this button_shape in your button’s code as

android:background=”@drawable/button_shape”

here’s the code

main.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <TextView   android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Hello Android from NetBeans"/>

    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nishant Nair"
            android:padding="5dip"
            android:layout_gravity="center"
            android:background="@drawable/button_shape"
            />

</LinearLayout>

you can add an image to your button by using drawable

android:drawableTop=”@drawable/pdf”

in your button’s xml code

this will look like this

Enjoy.. 😉 !!!!!!!

Advertisements
Categories: Android Tags: ,
%d bloggers like this: