Search Unity

For an introduction into Android themes and styles, feel free to refer to Google documentation: http://developer.android.com/guide/topics/ui/themes.html

If you are designing a game, where the world and the UI are rendered full-screen by Unity, why care about the themes?

First of all, you may want to display a WebView, or another sort of dialog with standard Android interface, and it will by default inherit the applications theme.

Second, when clicking an InputField or calling TouchScreenKeyboard.Open(), you have the keyboard displayed along with the input box. Themes are applied to this input box.

At the moment of writing this post, Google has three main theme families:

  • Material (available for Android 5.0 Lollipop and later)
  • Holo (available for Android 4.0 Ice Cream Sandwich and later)
  • Anything pre-Holo.

Let’s check it out:

Holo

image00

Material

image01

NoTitleBar

image02

Third point of applying the themes – if you want to get your game or app featured by Google, you have to apply the latest theme available at the moment (now this is Material).

However, there is another way to deal with the themes – appcompat library, which is a part of the Android Support Library package. Google publishes this library for the developers to be able to apply recent themes to older devices, for example, Material to pre-Lollipop devices. This is a good way to go with regular Android apps, however we at Unity do not include appcompat into our standard package for a number of reasons (apk size being the most important). You can add appcompat to a Unity game yourself if you’d like to – either as a plugin or in Android Studio after exporting the project.

Now back to Unity. If you take a look at our default manifest, you will see the following:

By default, we are applying the theme that is available on all supported devices (Android 2.3 Gingerbread and later). Good news is that we now allow you to override this setting in your own manifest (more details on overriding the manifest are here, long story short – place your manifest into Assets/Plugins/Android/AndroidManifest.xml, but beware as it overrides our manifest completely). Setting your own theme works starting from version:

  • Unity 4.6 family – from Unity 4.6.4 Patch 4;
  • Unity 5.0 family – from Unity 5.0.1 Patch 4;
  • Unity 5.1 – from the initial release.

However please don’t rush overriding the manifest to change the theme! We have one more thing for you ☺ At runtime, on initialization, Unity Android player checks whether you changed the default Unity theme (Theme.NoTitleBar.Fullscreen):

  • If you did change it, we respect your choice.
  • If you did not, we check the device API level, and apply Material for Lollipop and later, or Holo for Ice Cream Sandwich and later, on the fly.

So the bottom line is – if you don’t override the default Unity theme in Android manifest, we will apply the latest available theme for the device running the game, at runtime. Please be careful when overriding the manifest completely. If you don’t specify any theme at all for your application, Android will choose Theme.DeviceDefault, which may result in different and possibly disappointing results on different devices. You may want to keep the Unity’s default

in your custom manifest, and we will take care of dynamically applying the best theme for you.

12 replies on “Android Themes in Unity”

Hi,

«… This is a good way to go with regular Android apps, however we at Unity do not include appcompat into our standard package for a number of reasons (apk size being the most important). You can add appcompat to a Unity game yourself if you’d like to – either as a plugin or in Android Studio after exporting the project. »

Does this mean if I am building a Android Plugin for Unity which uses appcompat library, I will not be able to build the Unity because the appcompat library is not included? And so to tackle this, the appcompat library needs to be added manually to Assets/Plugins/Android/?

I’ve tried this but seems like the app has a runtime error when I call/start an activity from the android plugin library I created that needs the Appcompat lib.

Thanks for this article, I hadn’t considered how the Android theme could affect full screen games. So, I think I’m I right in thinking that if I do nothing, the manifest will show that I have the gingerbread and lower theme, but at runtime this will be changed to a later version if available on the device?

My reason for asking is I’m wondering how this affects Google’s ranking on the Play Store (and chances of being featured, as you mentioned) – do you know if Google would count this as not supporting the latest theme, simply because it’ not in the manifest of the APK?

On another note, it’s worth pointing out that the text input isn’t the only place your theme can make a difference – in lollipop the apps theme colours show on the task switcher, so it could be useful to include some theme colours to help with branding.

While we’re on the subject of the Play Store (sorry, last question!) do you know if anything is being done about Unity games showing as «designed for phones» even though they would work fine on tablets too? I’ve seen some people asking on the forums, but nobody seems to be able to answer why this is happening.

What if the custom Assets/Plugins/Android/AndroidManifest.xml contains the default android:theme="@android:style/Theme.NoTitleBar" ? Does this cause the Android player on initialization use it instead of changing it to the best on the fly?

My custom AndroidManifest.xmlcreated by merging from different plugins contains for example this»

How this changes the behaviour of the Android player? I would like to have the best theme applied on the fly, but I’m not sure if the above allows this.

Additionaly some plugins add their own activities and themes for them, e.g. android:theme="@android:style/Theme.Translucent.NoTitleBar"

How to control all of this to get best results and still a chance to be featured (if there’s any ;)

Cheers,
Rafal

Hi all
I want to ask why unity does not allow interacting UI while keyboard is open? Isnt the API unity provides us for keyboard really powerless?

Minor correction: I believe your example images for «Material» and «Holo» are mixed up. The Holo theme has the small spikes at the beginning and end of the input whereas the Material theme has just a flat underline indicating the input.

Comments are closed.