Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 61 Next »

Introduction

Android allows you to set the appearance of your application using themes. A theme specifies default colors, fonts, and images, for an Android activity or an entire application. Your application can use the device's built-in themes, or include custom themes. Titanium's root splash screen activity uses "Theme.Titanium" by default. All other activity windows will use "Theme.MaterialComponents.*" derived theme as of Titanium 9.3.0. Older Titanium versions will use "Theme.AppCompat" for all activity windows.

To update the look of your application, you can either:

  • Use a different built-in Android theme
  • Use a Titanium-defined theme
  • Create a custom theme and define the elements you want to change
  • Use the Android Material Theme to quickly customize the theme's color palette
  • Use third-party tools to help you generate a custom theme

You can also assign a unique theme to an activity instead which would override the application's assigned theme.

Android AppCompat themes

Icon
As of Titanium 10.0.0, AppCompat themes are no longer supported. Using them will cause a runtime error occur. This is because Titanium 10.0.0 uses native material widgets/views that require MaterialComponents based themes to work.

Android provides some built-in themes to easily change the overall appearance of your application. To use a built-in theme, you need to create a theme XML file for your project, specify the built-in theme you want to use, and reference it in the Android manifest section of your tiapp.xml file.

First, create a theme XML file in ./platform/android/res/values. For Titanium SDK 8.x.x and older, do NOT name the file theme.xml since it will overwrite Titanium's built-in theme.xml file. This is not an issue with Titanium 9.0.0 and higher.

In the theme XML file, add the theme you want to use. Themes defined by the Android system, excluding the AppCompat ones, are prefaced with @android:style (for example, @android:style/Theme.Translucent). Custom themes defined by the application are prefaced with @style (for example, @style/Theme.MyTheme). For example, the file below adds support for some of the common built-in Android themes.

platform/android/res/values/builtin_themes.xml

Finally, to use a theme in your application, modify the Android section of your tiapp.xml file to reference the style name you want to use:

The screenshots below show the difference between the various built-in themes:

AppCompat.Light

AppCompat/HoloAppCompat.Light.DarkActionBar

Titanium material themes

As of Titanium 10.0.0, all of the below are material based themes which support displaying Google's native material widgets/views. You can apply these themes to your application or individual activities instead of creating your own custom theme.

Theme NameSDK VersionDescription
Theme.Titanium1.0.0

Theme applied to the root splash screen activity only. Does not show a top action bar. As of 10.0.0, the top status bar and bottom navigation bar are translucent.

This splash theme inherits from a material theme as of Titanium 9.3.0.

Theme.Titanium.DayNight10.0.0

Supports light/dark material theme switching. Shows an action bar and status bar.

This is the default application theme as of Titanium 10.0.0.

Theme.Titanium.DayNight.NoTitleBar10.0.0Supports light/dark material theme switching without an action bar. Shows a status bar.
Theme.Titanium.DayNight.Fullscreen10.0.0Supports light/dark material theme switching without an action bar and status bar.
Theme.Titanium.Dark10.0.0Dark material theme. Shows an action bar and status bar.
Theme.Titanium.Dark.NoTitleBar10.0.0Dark material theme without an action bar. Shows a status bar.
Theme.Titanium.Dark.Fullscreen10.0.0Dark material theme without an action bar and status bar.
Theme.Titanium.Light10.0.0Light material theme. Shows an action bar and status bar.
Theme.Titanium.Light.NoTitleBar10.0.0Light material theme without an action bar. Shows a status bar.
Theme.Titanium.Light.Fullscreen10.0.0Light material theme without an action bar and status bar.
Theme.AppDerived.NoTitleBar10.0.0

Derives from <application/> assigned theme. Excludes the action and keeps the status bar.

Can only be applied to activities and not the application.

Theme.AppDerived.Fullscreen10.0.0

Derives from <application/> assigned theme. Excludes the action bar and status bar.

Can only be applied to activities and not the application.

Theme.AppDerived.Translucent10.0.0

Derives from <application/> assigned theme and applies a transparent background.

Can only be applied to activities and not the application.

Theme.AppDerived.Translucent.NoTitleBar10.0.0

Derives from <application/> assigned theme, applies a transparent background, excludes action bar, and keeps the status bar.

Can only be applied to activities and not the application.

Theme.AppDerived.Translucent.Fullscreen10.0.0

Derives from <application/> assigned theme, applies a transparent background, excludes action bar, and excludes status bar.

Can only be applied to activities and not the application.

Titanium deprecated themes

The below Titanium defined themes have been deprecated as of 10.0.0. The below should only be used by older Titanium versions.

 

Theme NameSDK VersionDescription
Theme.MaterialComponents.Fullscreen.Bridge9.3.0Based on Theme.MaterialComponents.Bridge. Has no action bar or status bar.
Theme.Titanium.NoTitleBar9.3.0

Based on the application's assigned theme, which uses Theme.MaterialComponents.Bridge by default. Has no action bar.

Can only be applied to activities and not the application.

Theme.Titanium.Fullscreen9.3.0

Based on the application's assigned theme, which uses Theme.MaterialComponents.Bridge by default. Has no action bar or status bar.

Can only be applied to activities and not the application.

Theme.Titanium.Translucent.NoTitleBar9.3.0

Based on the application's assigned theme, which uses Theme.MaterialComponents.Bridge by default. Has a transparent background and no action bar.

Can only be applied to activities and not the application.

Theme.Titanium.Translucent.Fullscreen9.3.0

Based on the application's assigned theme, which uses Theme.MaterialComponents.Bridge by default. Has a transparent background. Has no action bar or status bar.

Can only be applied to activities and not the application.

Theme.AppCompat.NoTitleBar

4.2.0Based on Theme.AppCompat. Has no action bar.

Theme.AppCompat.NoTitleBar.Fullscreen

4.2.0Exactly the same as Theme.AppCompat.Fullscreen above.
Theme.AppCompat.Fullscreen3.4.0Based on Theme.AppCompat. Has no action or status bar.
Theme.AppCompat.Translucent3.4.0

Based on Theme.AppCompat. Has a transparent background.

Theme.AppCompat.Translucent.NoTitleBar3.4.0Based on Theme.AppCompat. Has a transparent background and no action bar.
Theme.AppCompat.Translucent.NoTitleBar.Fullscreen3.4.0Based on Theme.AppCompat. Has a transparent background. Has no action bar or status bar.

Applying Titanium themes

To apply a theme globally, then in the tiapp.xml file you must set the android:theme attribute to the theme name in the <application/> XML element of the Android manifest section. As of Titanium 9.0.0, you can use a Theme.MaterialComponents.* based theme to support Google's material design. Note that Titanium 10.0.0 and higher requires a material based theme or else a runtime error will occur.

For example, do the below to set up a Titanium 10.x.x app to use a dark only theme (ie: do not support dark/light theme switching).

Do the below to set up a Titanium 10.x.x app to not show an action bar, but keep dark/light theme switching.

To change the theme on a per-window basis, set the theme name to a Window's theme property. For Titanium 10.0.0 and higher, you should use a Theme.AppDerived.* based theme since they are based on the theme assigned to <application/>, making it look consistent with other windows. For Titanium versions older than 9.3.0, you should use a Theme.AppCompat.* based theme.

Custom themes

To define custom themes, place the theme XML files with your custom styles in the platform/android/res/values folder. For Titanium SDK 8.x.x and older, do NOT name the file theme.xml since it will overwrite Titanium's built-in theme.xml file. This is not an issue with Titanium 9.0.0 and higher.

Note that you can also define version-specific themes by adding a values-v<version> folder. For example a theme defined under a values-v23 folder will be used for API Level 23 (Android 6) and above. A theme defined under the values-v29 folder will be used for API Level 29 (Android 10) and above.

For example, if you want your theme to be based on the Light theme, create the following theme file:

platform/android/res/values/mytheme.xml

If you want to support dark/light theme switching, then add the following under values-night to define a custom dark theme. This is supported as of Titanium 10.0.0.

platform/android/res/values/colors.xml

To use the above custom "Theme.MyTheme" in your application, modify the Android section of your tiapp.xml file:

Refer to Android Developers: Styles and Themes for detailed information on customizing items.

Material theme

As of Titanium 9.3.0, apps use the Theme.MaterialComponents.Bridge by default. You do not need to create your own theme.

For older Titanium SDK versions, you'll need to create a custom theme. For 9.0.0 and above, it should be extend a Theme.MaterialComponents.* based theme.  For Titanium 8.x.x and older, it should extend  a Theme.AppCompat.* based theme.

With a material based theme, you'll be able to set additional color palette attributes.

MaterialThemeAnnotated

Color Palette AttributeDescription
colorPrimaryDarkSets the color of the status bar. Only works with Android 5.0 (API 21) and greater.
colorPrimarySets the color of the action bar.

colorAccent

Sets the accent color, which is usually the color of the control when it is activated.

colorControlNormal

Sets the color of the control when it is not activated.

colorControlActivated

Sets the color when the control is activated. Overwrites the colorAccent attribute.

colorControlHighlight

Sets the color when the user clicks on a control. Only works with Android 5.0 (API 21) and greater.

colorSwitchThumbNormal

Sets the color of a toggle switch's thumb when it is not enabled. Only works with Android 5.0 (API 21) and greater.
android:colorButtonNormalSets the color of a button when it is not pressed. Only works with Android 5.0 (API 21) and greater.
android:colorEdgeEffectSets the edge effect color when the user tries to scroll beyond the content's boundaries. Only works with Android 5.0 (API 21) and greater.

android:navigationBarColor

Sets the color of the navigation bar (the bar that appears at the bottom of the device that contains the Back, Home and Recent App buttons). Only works with Android 5.0 (API 21) and greater.

android:textColorPrimary

Sets the color of text on controls. Prior to Android 5.0, this only sets the color of the action bar title and overflow menu.

Example

The following XML file below defines a theme that extends a material based theme and applies additional color palette attributes. This theme was applied to the application in the previous screen shot.

platform/android/res/values/custom_theme.xml

Theme comparison

The following table compares the same application when using different Android versions and themes. Note that the Android 4.4. screenshots use the old style toggle button due to Android bug #78262.

Example Material Theme / Android 5.0Example Material Theme / Android 4.4Default AppCompat / Android 4.4


Material theme further reading

Override a theme

If you have a global theme set, the application can override the theme for a window or activity, or if you want to specify a custom theme for a specific window or activity.

Override a window theme

Use the theme property to override the global theme for an individual window. Set the property to the name of the theme you want to apply to the window. The property can only be set when creating the Window object and cannot be changed after it is set. For Titanium 9.3.0 and higher, you should use a Theme.Titanium.* based theme since they are based on the theme assigned to <application/>, making it look consistent with other windows. For Titanium versions older than 9.3.0, you should use a Theme.AppCompat.* based theme.

Override an activity theme

As you can see in the previous examples, an application-wide theme can be specified in the <application> element of your tiapp.xml file, but it can also be overridden on a per-activity basis. These activities are defined in the AndroidManifest.xml file, generated by the build process. You can find the generated AndroidManifest.xml file in the build/android folder under your project folder. Inside the AndroidManifest.xml, you'll find code like this:

Icon

The build folder is hidden by default in Studio's App Explorer and Project Explorer views, but visible in the Navigator view.

To override the theme for one of these activities, copy the activity definition into the tiapp.xml file, and place it inside the <android><manifest> element. The <activity> element must be nested inside an <application> element, as in the original AndroidManifest.xml file. The end result should look something like this:

Icon

If you change the name of the application, you will need to copy the newly generated android:name value from the AndroidManifest.xml file and overwrite the old value in the tiapp.xml file.

Custom theme generator

Android Action Bar Style Generator

The Android Action Bar Style Generator is a website tool that builds and generates an Android Action Bar style based on the customizations you select.  This tool generates the XML files and graphic assets you need and packages them in to a ZIP file, which you can unpack in your project.

To create a custom Action Bar style:

  1. Go to Android Action Bar Style Generator.
  2. Enter a name for your style.  This name will be used to reference your style in the Android manifest.  If you want to use a theme generated by the Android Holo Colors Generator, do not use the same name.
  3. For Style Compatibility, use AppCompat.
  4. Choose the style customizations you want to use.
  5. Click Download .ZIP button near the button of the web page to download your custom theme.

Once you have your custom Action Bar style, unpack the ZIP file and copy the res folder to your project's platform/android folder.  Then, modify your tiapp.xml file to use the custom style, for example:

Further reading

  • No labels