unity android_Unity中的Android主题
unity android
For an introduction into Android themes and styles, feel free to refer to Google documentation: http://developer.android.com/guide/topics/ui/themes.html
有关Android主题和样式的介绍,请随时参考Google文档: 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?
如果您要设计游戏,而Unity则以全屏方式呈现世界和UI,那么为什么要关心主题?
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.
首先,您可能想要显示一个WebView或其他具有标准Android界面的对话框,并且默认情况下它将继承应用程序主题。
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.
其次,当单击InputField或调用TouchScreenKeyboard.Open()时,将显示键盘和输入框。 主题将应用于此输入框。
At the moment of writing this post, Google has three main theme families:
在撰写本文时,Google具有三个主要主题系列:
- Material (available for Android 5.0 Lollipop and later) 材料(适用于Android 5.0 Lollipop及更高版本)
- Holo (available for Android 4.0 Ice Cream Sandwich and later) Holo(适用于Android 4.0 Ice Cream Sandwich及更高版本)
- Anything pre-Holo. 霍洛之前的一切。
Let’s check it out:
让我们来看看:
Holo
霍洛
Material
材料
NoTitleBar
NoTitleBar
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).
应用主题的第三点–如果您想让您的游戏或应用被Google精选,则必须应用当前可用的最新主题(现在是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.
但是,还有另一种处理主题的方法– appcompat库,它是Android支持库程序包的一部分 。 Google发布了该库,供开发人员使用,以将最新主题应用于较旧的设备,例如,将Material应用于预棒棒糖设备 。 这是与常规Android应用程序搭配使用的好方法,但是出于多种原因(apk大小是最重要的),我们Unity并未将appcompat包含到我们的标准软件包中。 如果需要,您可以自己将appcompat添加到Unity游戏中-作为插件或在导出项目后在Android Studio中添加。
Now back to Unity. If you take a look at our default manifest, you will see the following:
现在回到Unity。 如果您查看我们的默认清单,将会看到以下内容:
1
|
1
|
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:
默认情况下,我们将应用所有支持的设备(Android 2.3 Gingerbread及更高版本)上可用的主题。 好消息是,我们现在允许您在自己的清单中覆盖此设置(有关覆盖清单的更多详细信息,在这里 ,长话短说–将您的清单放入Assets / Plugins / Android / AndroidManifest.xml中,但请注意,因为它会覆盖我们的清单完全体现)。 从版本开始设置自己的主题即可:
- Unity 4.6 family – from Unity 4.6.4 Patch 4; Unity 4.6家族–来自Unity 4.6.4补丁4;
- Unity 5.0 family – from Unity 5.0.1 Patch 4; Unity 5.0系列–来自Unity 5.0.1补丁4;
- Unity 5.1 – from the initial release. Unity 5.1 –从初始版本开始。
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):
但是,请不要急于覆盖清单来更改主题! 我们还有另一件事给您☺在运行时,初始化时,Unity Android播放器会检查您是否更改了默认的Unity主题(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. 如果您没有这样做,我们将检查设备API级别,并即时应用“棒棒糖”和“更高版本”的“材料”或“冰淇淋三明治”和更高版本的“ Holo”。
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
因此,最重要的是–如果您不覆盖Android清单中的默认Unity主题,我们将在运行时为运行游戏的设备应用最新的可用主题。 完全覆盖清单时,请小心。 如果您根本没有为应用程序指定任何主题,则Android将选择Theme.DeviceDefault,这可能导致在不同设备上产生不同的结果,并且可能令人失望。 您可能要保留Unity的默认设置
1
|
1
|
in your custom manifest, and we will take care of dynamically applying the best theme for you.
在您的自定义清单中,我们将为您动态地应用最佳主题。
翻译自: https://blogs.unity3d.com/2015/07/16/android-themes-in-unity/
unity android