vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Tuesday, September 11, 2012

Create custom Dashboard icon with text in android application


Here I would like to share the bit of useful information about android application. When creating android application everyone have need to create or show button in an application. Here I share simple and elegant method to create android button using linear layout.
Ina previous article I wrote to use image in a button, for your reference I mention the link as below


Requirement needed to create
1.       First choose your icon button as in same width and height.
Normally android they are two normally used to create button icon i.e. Linear layout or grid view layout
Here I chose linear layout with horizontal orientation
First needs to create style code in styles.xml files in values folder.
File style.xml
Code:
<style name="DashboardButton">
        <item name="android:layout_gravity">center_vertical</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:drawablePadding">2dp</item>
        <item name="android:textSize">16dp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#034486</item>
        <item name="android:background">@drawable/button</item>
         <item name="android:layout_weight">1</item>
         </style>




In your main layout copy the below code and change the image you want to set for the button..
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"      
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="40dp" >

            <Button
                android:id="@+id/btn1"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img1"
                android:text="Add"
                android:textSize="14dp" />

            <Button
                android:id="@+id/btn2"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img2”
                android:text="Delete" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="20dp" >

            <Button
                android:id="@+id/btn3"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img3"              
                android:text="edit"
                android:textSize="14dp" />

            <Button
                android:id="@+id/btn4"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img4"              
                android:text="Display"
                android:textSize="14dp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="20dp" >

            <Button
                android:id="@+id/btn5"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img5"
               
                android:text="Store"
                android:textSize="14dp" />
              
        <Button
                android:id="@+id/btn6"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img6"
                android:text="History"
                android:textSize="14dp" />
     

        </LinearLayout>
    </LinearLayout>


Here store all the images in drawable folder and we set the style for every button as dashboard button
That’s it now you can run view the images are aligned in  your layout
Post your comments here 

0 comments:

Post a Comment