Android: how to customize default themes and styles
March 18, 2010 3 Comments
What is Style?
A style is a collection of properties that specify the look and format for a View
or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
Default Styles of android platform – here
What is Theme?
A theme is a style applied to an entire Activity
or application, rather than an individual View
(as in the example above). When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports.
Default themes of android platform – here
To customize Themes and Styles of android platforms, you need to specify the attributes that are necessary to change. You may do the following things:
- Find out default attributes of themes and styles which are needed to change as your requirements. If necessary see default attributes.
- Derive custom themes and styles by inheriting from default platform’s themes and styles.
- Modify/change necessary attributes of these.
- Specify this theme in activity declaration in AndroidMenifest.xml file.
- Specify if necessary styles in view declaration in layout out file.
- that’s all.
Details code examples are here:
Custom themes for Window title bar, Listview, and Dialog in …/res/values/themes.xml –
<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<style name=”customTheme1″ parent=”android:Theme”>
<item name=”android:windowTitleSize”>25dip</item>
<item name=”android:windowTitleBackgroundStyle”>@style/WindowTitleBackground1</item>
<item name=”android:listViewStyle”>@style/ipicsListView</item>
<item name=”android:listViewWhiteStyle”>@style/ipicsListView</item>
</style>
<style name=”customDialog” parent=”android:Theme.Dialog”>
@drawable/my_panel_background
</style>
</resources>
Custom Styles in …/res/values/styles.xml –
<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<style name=”WindowTitleBackground1″ parent=”android:WindowTitleBackground”>
@drawable/custom_header
</style>
<style name=”customListView” parent=”@android:style/Widget.ListView”>
@drawable/list_selector_background_focus
<item name=”android:background”>@android:color/white</item>
<item name=”android:cacheColorHint”>@color/white</item>
</style>
</resources>
AndroidaManifest.xml –
<activity android:name=”.LoginActivity” android:theme=”@style/customTheme”></activity>
<activity android:name=”.ProductsListActivity” android:theme=”@style/customTheme”></activity>
References:
http://developer.android.com/guide/topics/ui/themes.html#Properties
I think you have amazing site. i will subscribe this one. thanks
I think you have amazing site. i will bookmark this one. thanks
Thanks 🙂