1、正常打包
Unity选择Windowed,无效
2、代码设置非全屏
Screen.fullScreen = false; 结果,状态栏黑色
3、修改jar包
未测试,链接:Click
4、调用Android修改配置
public static void SetupAndroidTheme(int primaryARGB, int darkARGB, string label = null)
{
#if UNITY_ANDROID && !UNITY_EDITOR
label ??= Application.productName;
Screen.fullScreen = false;
AndroidJavaObject activity = MessageCenter.GetAndroidJavaObject();
activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
AndroidJavaClass layoutParamsClass = new AndroidJavaClass("android.view.WindowManager$LayoutParams");
int flagFullscreen = layoutParamsClass.GetStatic<int>("FLAG_FULLSCREEN");
int flagNotFullscreen = layoutParamsClass.GetStatic<int>("FLAG_FORCE_NOT_FULLSCREEN");
int flagDrawsSystemBarBackgrounds = layoutParamsClass.GetStatic<int>("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
AndroidJavaObject windowObject = activity.Call<AndroidJavaObject>("getWindow");
windowObject.Call("clearFlags", flagFullscreen);
windowObject.Call("addFlags", flagNotFullscreen);
windowObject.Call("addFlags", flagDrawsSystemBarBackgrounds);
int sdkInt = new AndroidJavaClass("android.os.Build$VERSION").GetStatic<int>("SDK_INT");
int lollipop = 21;
if (sdkInt > lollipop)
{
windowObject.Call("setStatusBarColor", darkARGB);
string myName = activity.Call<string>("getPackageName");
AndroidJavaObject packageManager = activity.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject drawable = packageManager.Call<AndroidJavaObject>("getApplicationIcon", myName);
AndroidJavaObject taskDescription = new AndroidJavaObject("android.app.ActivityManager$TaskDescription", label, drawable.Call<AndroidJavaObject>("getBitmap"), primaryARGB);
activity.Call("setTaskDescription", taskDescription);
}
}));
#endif
}
public static int ToARGB(Color color)
{
Color32 c = (Color32)color;
byte[] b = new byte[] { c.b, c.g, c.r, c.a };
return System.BitConverter.ToInt32(b, 0);
}
该方法测试成功
5、Android端修改
如果导出Android工程,二次开发,则可修改Android代码 也就是将上面CallAddroid的方法,在Android完成,注意:Unity中保留设置非全屏代码
public static void setNonFullScreen(Activity currentActivity, int primaryColor, int darkColor)
{
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
currentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
currentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
if(Build.VERSION.SDK_INT > 21)
{
currentActivity.getWindow().setStatusBarColor(darkColor);
PackageManager packageManager = currentActivity.getPackageManager();
Drawable drawable = null;
try {
drawable = packageManager.getApplicationIcon(currentActivity.getPackageName());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(
String.valueOf(packageManager.getApplicationLabel(currentActivity.getApplicationInfo())),
drawableToBitmap(drawable),
primaryColor);
currentActivity.setTaskDescription(taskDescription);
}
}
});
}
public static Bitmap drawableToBitmap(Drawable drawable) {
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap.Config config =
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
|