Tutorial details

Android Styles and Themes - Tutorial | App Code for Sale | Preview

Android Styles and Themes - Tutorial | Android Tutorial

This tutorial describes how to create and use Styles and Themes in Android application.

Overview PAGE TOP

This tutorial describes how to create and use Styles and Themes in Android application.

1.1. Android design page PAGE TOP

The Android design page contains advice for styling your application. You find the design page under the following URL.

http://developer.android.com/design/index.html

This page also contains several downloadable resources, e.g. an icon set for the ActionBar.

1.2. Styles PAGE TOP

Styles in Android allow to define the look and feel of Android application in external files. Styles can get assigned to Views.

You can define styles in XML and assign them to these elements. This way you only have to set common attributes once and can later change the look in one central place.

To define a style, save an XML file in the /res/values directory of your project. The root node of the XML file must be .

The following styles.xml XML file can be created in the /res/valuesl folder.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="text">
        <item name="android:padding">4dip</item>
        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
        <item name="android:textColor">#000000</item>
    </style>
    <style name="layout">
        <item name="android:background">#C0C0C0</item>
    </style>
</resources>

You assign the style attribute to your elements, for example to the text elements via style=”@style/text.

1.3. Attributes PAGE TOP

You can also refer to individual attributes of Android styles. For example the following will define button with the Android 4.0 button style.

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

    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/Button01"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Show" />

        <Button
            android:id="@+id/Button02"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Change" />
    </LinearLayout>

    <EditText
        android:id="@+id/myView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

</LinearLayout> 

android2013.2.132.png

1.4. Themes PAGE TOP

A theme is a style applied to an entire activity or application, rather than an individual View (as in the example above).

The next example show how to define your own Theme while extending a platform theme.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="android:Theme.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@color/translucent_red</item>
        <item name="android:listViewStyle">@style/MyListView</item>
    </style>

    <style name="MyListView" parent="@android:style/Widget.ListView">
        <item name="android:listSelector">@drawable/ic_menu_home</item>
    </style>

</resources>

Reference PAGE TOP

http://www.vogella.com/articles/AndroidStylesThemes/article.html

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.