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 Comments

Subscribe to comments

Comments are closed.

  1. 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.

    1. Hi Albert,

      Yes you would need to include appcompat library yourself (into Assets/Plugins/Android/). As for your failing plugin – I think APK build would have failed if dependent library was missing. Please share your issues on the forums and post the link here, I’ll take a look.

  2. 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.

    1. Hi RIch,

      Thanks for the note on color/branding!

      We do change the theme at runtime based on the device API level. Yes Google will consider you are not using latest theme in your APK – that’s what I know. To get featured, you need Material (minSdk = 21) or AppCompat (add Support library) – I’ve covered that in this post in brief. We at Unity don’t do any of these for a number of reasons, but you are welcome to add Support library on your own. (please let me know if you face any issues).

      On the “designed for phone” issue – could you share the link to the forums? I’ll reply there and see whether we can fix it.

      Thanks!

      1. Thanks for replying Yury. I hadn’t seen anything on the Unity forums aroun the “designed or phones” issue, but I’m having it with my game, as an example: https://play.google.com/store/apps/details?id=co.uk.toiletboy.toiletboy

        …and I read about others having the issue here too:
        http://unitycoder.com/blog/2014/03/18/your-apk-does-not-seem-to-be-designed-for-tablets/

        Thanks :)

        1. Rich, you may want to create a forum thread to discuss it further. It does not look like a trivial issue with the manifest. Thanks!

  3. 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

    1. Hey Rafal,

      The simplest way to get featured is to set minSdk = 21 and apply material theme! (just kidding)

      If Unity activity has Theme.NoTitleBar.Fullscreen applied, then we auto upgrade it. Any other theme – we don’t touch it, because you have probably changed it intentionally.

      For all the other activities in your app – feel free to apply what you find appropriate.

      I would say trying to add support library and applying appcompat makes sense for me, if you want to get featured. (never tried though. Should do that and write another blog post!)

  4. 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?

    1. When you call TouchScreenKeyboard.Open(), what you see is a simple Dialog with an EditText and a Button displayed over Unity. It means that the Unity window is losing focus, hence it cannot be interacted. As soon as you click outside the dialog (somewhere in the game), the dialog is dismissed, and the focus goes back to Unity. This is how Android OS works.

      The keyboard is rendered and handled by Android OS itself, so we do not have much control over that, other than the keyboard type – text, numeric, …

  5. 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.

    1. True! Fixed that. Thanks!