Wednesday, 23 July 2014

Creating Designer Views Using Styles in Android

Hi Guys, I am Mukesh, working as Android developer from past 2 years. I am writing my first blog so please encourage me by liking this if you really like this one. so that i can go for more blogs.

I am Creating Designer/ Stylish Button rather than simple default android Button/any view.


For this we Just need to perform two steps:

1. create xml in drawable folder for design.
2. set the drawable onto button in layout xml.

Sample Code:

Step 1:  bluebuttonstyle.xml( Drawable Folder )

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape
        android:shape="rectangle">
            <solid android:color="@color/color_BlueButtonBorder" />
<corners android:radius="5dp"></corners>
        </shape>
   </item>

   <item android:bottom="@dimen/dimen_buttonborderheight">
      <shape
        android:shape="rectangle">
            <corners android:radius="5dp"></corners>
            <solid android:color="@color/color_BlueButtonTop" />
        </shape>
   </item>

</layer-list>



 Step 2:

buttonlayout.xml

<LinearLayout ..........
>
...
<Button
         android:id="@+id/btn_submit"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:background="@drawable/bluebuttonstyle"
          android:text="Submit" />
...
</LinearLayout>

In this layout file, we have applied above mentioned style onto the Button in buttonlayout.xml . So in UI design you will get stylish Button.

We are done with it...

Thanks... Please like this if you really Like it...

1 comment: