Android Themes in 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:
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 ComentariosSubscribirse a los comentarios
Ya no se aceptan más comentarios.