Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Changing Android ActionBar Theme and Android Style

Customizing the overall App Style

This guide has been updated for Titanium SDK 3.3.0 which uses AppCompat to bring the ActionBar to Android 2.3.x

Android has a build-in theming system. Using this feature you can easily change the base color Android uses for its controls across your app, allowing you to provide better branding and personalization, while maintaining Android's UI and UX.

Android built-in themes are:

  • Holo (Mostly Black and Cyan)
  • Holo Light (Mostly White and Gray)
  • Holo Light with Dark ActionBar (Like the previous with a dark gray ActionBar)

By following a couple simple steps, you can build your own themes and use them for your Titanium apps.

  • Create theme at http://android-holo-colors.com/
    • Set Min SDK Version to <11, otherwise it'll generate HOLO resources that are not compatible with AppCompat.
    • Make sure you leave Switch, Switch JellyBean and Navigation Drawer as NO
    • Set compatibility to APPCOMPAT
    • For convenience and readability, give it a name that represents the color you're using, in this example I'm naming it Green
  • Download zip
  • Decompress and copy /res onto /platform/android/res
  • Modify tiapp.xml to point to the new theme

Go from this

 <android xmlns:android="http://schemas.android.com/apk/res/android">
 </android>

to this

<android xmlns:android="http://schemas.android.com/apk/res/android">
	<manifest>
	    	<application android:theme="@style/Green" />
    	    	<uses-sdk android:targetSdkVersion="19"/>
    </manifest>
</android>

Here your telling Titanium to add a custom manifest entry during the build process, in which you instruct Android to use your custom theme instead of the default one.

  • SDK Version 11 is Android 3.0 (Honeycomb). This is the first version that supports Holo Themes.
  • SDK Version 19 is Android 4.4 (KitKat). TargetSDK should always be the most recent SDK.

You can now run your app and all your controls should now be customized to the selected color.

Customizing the ActionBar Theme

Android also allows you to customize the ActionBar and ActionBar Tabs.

  • Create theme at http://jgilfelt.github.io/android-actionbarstylegenerator

    • If you select Light - Dark ActionBar as your base theme, your minSdkVersion must be >= 14
    • For convenience and readability, give it a name that represents your app. In this example I'm naming it Myappname (use a single word with no punctuation)
  • Download zip

  • Decompress and copy /res to /platform/android

  • Modify tiapp.xml to point to the new theme

Go from this

 <android xmlns:android="http://schemas.android.com/apk/res/android">
 </android>

to this

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <application android:theme="@style/Theme.Myappname"/>
        <uses-sdk android:minSdkVersion="11"/>
        <uses-sdk android:targetSdkVersion="19"/>
    </manifest>
</android>

Notice that when compared to the previous example, we're only making one very small change of specifying that the android:theme to be used is a style and not a theme.

You can now run your app and ActionBar should now be customized to the selected color.

Using both ActionBar Theme and App Style in the same app

You'll first need to create the ActionBar Theme as before, like in the previous example let's assume its name is Myappname. Add it to the tiapp.xml just as before:

 		<application android:theme="@style/Theme.Myappname"/>
  • Create the App Style just as before, and give it a name that represents the color, in this example Green.

  • Download zip

  • Decompress and merge the files onto /platform/android/res

  • Now you'll have to modify the settings for the previous theme (Myappname) to use this new one (Green) as its parent

  • Open /res/values/styles_myappname.xml

Change this

    <style name="Theme.Green" parent="@android:style/Theme.Holo.Light">

to

    <style name="Theme.Green" parent="@style/Green">

With this line, you have instructed your Myappname theme to use the Green style as its parent. The result will be both being used together in your app.


@AppWerft
Copy link

AppWerft commented Apr 1, 2014

Hi Ricardo,
you saved my day. I followed the first part of your instruction. Now I have a problem with the color in alert dialog boxes. There keeps cyan. This I have putted additionally in my colors_l2gorange.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="l2gorange_color">#f17b0d</color>
    <style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
        <item name="@android:background">#f17b0d</item>
        <item name="@android:textColor">#FAF5F7</item>  
  </style>
</resources> 

@taing
Copy link

taing commented Aug 10, 2014

great

@clemblanco
Copy link

clemblanco commented Jul 13, 2015

Is this still working with Ti SDK 4.x.x?

@bbcsolution
Copy link

bbcsolution commented Oct 15, 2021

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment