Unity AndroidManifest Style的修改

Unity 的AndroidManifest和安卓开发的AndroidManifest是有一点区别的,很多属性并不能使用,设置样式的时候需要注意。

Unity的AndroidManifest.xml文件在项目的Assets\Plugins\Android路径下,里面的application标签可以加theme、icon之类的属性来设置主题和图标等信息。

这里的theme不能像安卓那样直接写@android:style/Theme.Black.NoTitleBar,打包会报错。经过测试,自己定义的样式需要继承自UnityThemeSelector,然后定义的属性也是有限制的,只能使用部分属性。

如下在AndroidManifest.xml文件中使用了一个名为MyStyle的自定义样式:

1
2
3
4
5
6
7
8
9
10
11
12
13
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.splash">
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<application android:theme="@style/MyStyle">
<activity android:name="com.test.splash.SplashActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

需要在Assets\Plugins\Android\res\values路径下新建一个styles.xml文件,内容如下:

1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BlackText" parent="@style/UnityThemeSelector">
<item name="android:windowBackground">@android:color/black</item>
</style>
</resources>

然后在style标签下添加item定义样式,比如windowBackground是设置背景颜色。