Android: how to customize default themes and styles

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:

  1. Find out default attributes of themes and styles which are needed to change as your requirements. If necessary see default attributes.
  2. Derive custom themes and styles by inheriting from default platform’s  themes and styles.
  3. Modify/change necessary attributes of these.
  4. Specify this theme in activity declaration in AndroidMenifest.xml file.
  5. Specify if necessary styles in view declaration in layout out file.
  6. 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

Advertisements

About M Moniruzzaman
A passionate software engineer, have been developing applications on various platforms such as Android, iPhone, .Net (C#) technologies and web based ASP.NET, PHP, JavaScript, jQuery technologies for more than 10 years. Especially I have expertise on developing applications for Android and iPhone, as well as service oriented, client-server based applications where clients will be reside on Android/iPhone that communicate with WCF(.NET) service hosted on server. I have completed certification in Microsoft Certified Professional Developer (MCPD) on .Net 4 . I have completed my graduation in -- B.Sc. (Engineering) in Computer Science and Engineering, ShahJalal University of Science and Technology, Bangladesh. Thanks, M. Moniruzzaman (Zaman)

3 Responses to Android: how to customize default themes and styles

  1. dobby says:

    I think you have amazing site. i will subscribe this one. thanks

  2. Mercy says:

    I think you have amazing site. i will bookmark this one. thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: