Pages

Monday 17 February 2014

Styles & Themes in android


Style resource let your application maintain a consistent look and feel by enabling you to specify the attribute values used byviews.The most common use of themes and styles is to stores the colors,fonts for an application.

To create a style, use a style tag that includes a name attribute and contains on or more item tags.
Each item tag should include a name attribute used to specifiy the attribute(such as font color or size).

SKELETON CODE:


<style name="ButtonText">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:gravity">center</item>
    <item name="android:paddingLeft">10sp</item>
    <item name="android:layout_margin">3dp</item>
    <item name="android:textSize">30sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">2</item>
</style>
 

Styles support Inhertence using the parent attribute on the style.Make it easy to create simple variations.

CODE:


<style name="AppBaseTheme" parent="android:Theme.Light" >
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
</style>
 



No comments:

Post a Comment

Search Form