kiran kirve
kiran kirve

Reputation: 117

how to create a theme and xml style for android project

How can I create style theme file in android 4.2. How to apply this theme to all activity from android project. How can I set this style and theme to multiple screens?

http://developer.android.com/guide/topics/ui/themes.html>

Upvotes: 5

Views: 21089

Answers (1)

kyogs
kyogs

Reputation: 6836

Create a file named styles.xml in the your application's res/values directory. Add a root <resources> node. For each style or theme, add a <style> element with a unique name and, optionally, a parent attribute. The name is used for referencing these styles later, and the parent indicates what style resource to inherit from. Inside the <style> element, declare format values in one or more element(s). Each <item> identifies its style property with a name attribute and defines its style value inside the element. You can then reference the custom resources from other XML resources, your manifest or application code.

A theme is a style applied to an entire Activity or application,

<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>

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 <resources>.

<?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> 

In your AndroidManifest.xml apply the theme to the activities you want to style:

 <activity
        android:name="com.myapp.MyActivity"
        ...
        android:theme="@style/MyTheme"
        />

Upvotes: 9

Related Questions