关于Unity打包成Android后打开后会黑屏一段时间
产考连接:https://blog.csdn.net/qq_43278826/article/details/107557784
解决方案 1、首先,你在AndroidManifest.xml中的activity, 给activity设置android:theme, 例如这样:
<activity android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:theme="@android:style/Theme.Translucent"
android:name=".UnityPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
因为默认android:theme不设置的话或者不是透明的话,那么你后面再设置透明主题的话是不会有任何修改的。 2.接着在UnityPlayerActivity的onCreate里面设置成你自定义的style。
private UnityPlayerActivity _Activity;
@Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme( R.style.UnityThemeSelector_Logo);
super.onCreate(savedInstanceState);
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
_Activity=this;
}
- 自定义的style
在res目录下的values创建一个styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="UnityThemeSelector.Logo" >
<item name="android:windowBackground">@drawable/xbg</item>
<item name="android:background">@drawable/xbg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="UnityThemeSelector.Logo1">
<item name="android:windowBackground">@color/tt_transparent</item>
<item name="android:background">@color/tt_transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
- 当Unity 那边的代码启动完成后再 回调 Android 这边的修改setTheme
public void CloseSplash()
{
new Handler(Looper.getMainLooper()).post(new Runnable()
{
@Override
public void run()
{
_Activity.setTheme(R.style.UnityThemeSelector_Logo1);
}
});
}
到这基本就完了 最后 在华为某个手机型号下,会打开前白一下屏,不知道其他手机会不会!
|