打包安卓后打开app发现顶部的状态栏没有,没有时间电量等等

解决办法:

1.创建脚本:HideOrShowPhoneStatus


using System;
using System.Collections.Generic;
using UnityEngine;class AndroidStatusBar
{// Enumspublic enum States{Unknown,Visible,VisibleOverContent,TranslucentOverContent,Hidden,}// Constantsprivate const uint DEFAULT_BACKGROUND_COLOR = 0xff000000;#if UNITY_ANDROID// Original Android flagsprivate const int VIEW_SYSTEM_UI_FLAG_VISIBLE = 0;                                        // Added in API 14 (Android 4.0.x): Status bar visible (the default)private const int VIEW_SYSTEM_UI_FLAG_LOW_PROFILE = 1;                                // Added in API 14 (Android 4.0.x): Low profile for games, book readers, and video players; the status bar and/or navigation icons are dimmed out (if visible)private const int VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;                        // Added in API 14 (Android 4.0.x): Hides all navigation. Cleared when theres any user interaction.private const int VIEW_SYSTEM_UI_FLAG_FULLSCREEN = 4;                                // Added in API 16 (Android 4.1.x): Hides status bar. Does nothing in Unity (already hidden if "status bar hidden" is checked)private const int VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE = 256;                        // Added in API 16 (Android 4.1.x): ?private const int VIEW_SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512;        // Added in API 16 (Android 4.1.x): like HIDE_NAVIGATION, but for layouts? it causes the layout to be drawn like that, even if the whole view isn't (to avoid artifacts in animation)private const int VIEW_SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024;                // Added in API 16 (Android 4.1.x): like FULLSCREEN, but for layouts? it causes the layout to be drawn like that, even if the whole view isn't (to avoid artifacts in animation)private const int VIEW_SYSTEM_UI_FLAG_IMMERSIVE = 2048;                                // Added in API 19 (Android 4.4): like HIDE_NAVIGATION, but interactive (it's a modifier for HIDE_NAVIGATION, needs to be used with it)private const int VIEW_SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;                // Added in API 19 (Android 4.4): tells that HIDE_NAVIGATION and FULSCREEN are interactive (also just a modifier)private static int WINDOW_FLAG_FULLSCREEN = 0x00000400;private static int WINDOW_FLAG_FORCE_NOT_FULLSCREEN = 0x00000800;private static int WINDOW_FLAG_LAYOUT_IN_SCREEN = 0x00000100;private static int WINDOW_FLAG_TRANSLUCENT_STATUS = 0x04000000;private static int WINDOW_FLAG_TRANSLUCENT_NAVIGATION = 0x08000000;private static int WINDOW_FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = -2147483648; // 0x80000000; // Added in API 21 (Android 5.0): tells the Window is responsible for drawing the background for the system bars. If set, the system bars are drawn with a transparent background and the corresponding areas in this window are filled with the colors specified in getStatusBarColor() and getNavigationBarColor()// Current valuesprivate static int systemUiVisibilityValue;private static int flagsValue;#endif// Propertiesprivate static States _statusBarState;//        private static States _navigationBarState;private static uint _statusBarColor = DEFAULT_BACKGROUND_COLOR;//        private static uint _navigationBarColor = DEFAULT_BACKGROUND_COLOR;private static bool _isStatusBarTranslucent; // Just so we know whether its translucent when hidden or not//        private static bool _isNavigationBarTranslucent;private static bool _dimmed;// ================================================================================================================// INTERNAL INTERFACE ---------------------------------------------------------------------------------------------static AndroidStatusBar(){applyUIStates();applyUIColors();}private static void applyUIStates(){#if UNITY_ANDROID && !UNITY_EDITORint newFlagsValue = 0;int newSystemUiVisibilityValue = 0;// Apply dim valuesif (_dimmed) newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LOW_PROFILE;// Apply color values
//                if (_navigationBarColor != DEFAULT_BACKGROUND_COLOR || _statusBarColor != DEFAULT_BACKGROUND_COLOR) newFlagsValue |= WINDOW_FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;if (_statusBarColor != DEFAULT_BACKGROUND_COLOR) newFlagsValue |= WINDOW_FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;// Apply status bar valuesswitch (_statusBarState) {case States.Visible:_isStatusBarTranslucent = false;newFlagsValue |= WINDOW_FLAG_FORCE_NOT_FULLSCREEN;break;case States.VisibleOverContent:_isStatusBarTranslucent = false;newFlagsValue |= WINDOW_FLAG_FORCE_NOT_FULLSCREEN | WINDOW_FLAG_LAYOUT_IN_SCREEN;newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;break;case States.TranslucentOverContent:_isStatusBarTranslucent = true;newFlagsValue |= WINDOW_FLAG_FORCE_NOT_FULLSCREEN | WINDOW_FLAG_LAYOUT_IN_SCREEN | WINDOW_FLAG_TRANSLUCENT_STATUS;newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;break;case States.Hidden:newFlagsValue |= WINDOW_FLAG_FULLSCREEN | WINDOW_FLAG_LAYOUT_IN_SCREEN;if (_isStatusBarTranslucent) newFlagsValue |= WINDOW_FLAG_TRANSLUCENT_STATUS;break;}// Applies navigation values/*switch (_navigationBarState) {case States.Visible:_isNavigationBarTranslucent = false;newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE;break;case States.VisibleOverContent:// TODO: Side effect: forces status bar over content if set to VISIBLE_isNavigationBarTranslucent = false;newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE | VIEW_SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;break;case States.TranslucentOverContent:// TODO: Side effect: forces status bar over content if set to VISIBLE_isNavigationBarTranslucent = true;newFlagsValue |= WINDOW_FLAG_TRANSLUCENT_NAVIGATION;newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE | VIEW_SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;break;case States.Hidden:newSystemUiVisibilityValue |= VIEW_SYSTEM_UI_FLAG_FULLSCREEN | VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION | VIEW_SYSTEM_UI_FLAG_IMMERSIVE_STICKY;if (_isNavigationBarTranslucent) newFlagsValue |= WINDOW_FLAG_TRANSLUCENT_NAVIGATION;break;}*/if (Screen.fullScreen) Screen.fullScreen = false;// Applies everything nativelysetFlags(newFlagsValue);setSystemUiVisibility(newSystemUiVisibilityValue);#endif}private static void applyUIColors(){#if UNITY_ANDROID && !UNITY_EDITORrunOnAndroidUiThread(applyUIColorsAndroidInThread);#endif}#if UNITY_ANDROIDprivate static void runOnAndroidUiThread(Action target){using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){activity.Call("runOnUiThread", new AndroidJavaRunnable(target));}}}private static void setSystemUiVisibility(int value){if (systemUiVisibilityValue != value){systemUiVisibilityValue = value;runOnAndroidUiThread(setSystemUiVisibilityInThread);}}private static void setSystemUiVisibilityInThread(){//Debug.Log("SYSTEM FLAGS: " + systemUiVisibilityValue);using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){using (var window = activity.Call<AndroidJavaObject>("getWindow")){using (var view = window.Call<AndroidJavaObject>("getDecorView")){view.Call("setSystemUiVisibility", systemUiVisibilityValue);}}}}}private static void setFlags(int value){if (flagsValue != value){flagsValue = value;runOnAndroidUiThread(setFlagsInThread);}}private static void setFlagsInThread(){//Debug.Log("FLAGS: " + flagsValue);using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){using (var window = activity.Call<AndroidJavaObject>("getWindow")){window.Call("setFlags", flagsValue, -1); // (int)0x7FFFFFFF}}}}private static void applyUIColorsAndroidInThread(){using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){using (var window = activity.Call<AndroidJavaObject>("getWindow")){//Debug.Log("Colors SET: " + _statusBarColor);window.Call("setStatusBarColor", unchecked((int)_statusBarColor));//                                        window.Call("setNavigationBarColor", unchecked((int)_navigationBarColor));}}}}#endif// ================================================================================================================// ACCESSOR INTERFACE ---------------------------------------------------------------------------------------------/*public static States navigationBarState {get { return _navigationBarState; }set {if (_navigationBarState != value) {_navigationBarState = value;applyUIStates();}}}
*/public static States statusBarState{get { return _statusBarState; }set{if (_statusBarState != value){_statusBarState = value;applyUIStates();}}}public static bool dimmed{get { return _dimmed; }set{if (_dimmed != value){_dimmed = value;applyUIStates();}}}public static uint statusBarColor{get { return _statusBarColor; }set{if (_statusBarColor != value){_statusBarColor = value;applyUIColors();applyUIStates();}}}/*public static uint navigationBarColor {get { return _navigationBarColor; }set {if (_navigationBarColor != value) {_navigationBarColor = value;applyUIColors();applyUIStates();}}}*/
}

2.调用

    void Awake(){AndroidStatusBar.statusBarState = AndroidStatusBar.States.TranslucentOverContent;}

unity打包安卓显示手机顶部状态栏相关推荐

  1. UNITY 打包安卓APK

    UNITY 打包安卓APK 1,安装JDK.这个直接下就行了. 2,安装android sdk相关.这个比较蛋疼,官网是被墙的.有些网站的包还是需要访问墙外下载的.关键是找对那个能用的包(对我来说就是 ...

  2. unity打包安卓(anroid)APK及安卓环境设置

    打包APK:Unity部分下载安装及设置.电脑JDK下载安装及环境配置.安卓SDK安装及配置. 一.Unity部分下载安装及设置: 1.下载安装unity,各版本下载的官方网址:Unity官方下载_U ...

  3. uniapp 解决app头部导航和手机顶部状态栏叠加问题及样式拼接写法

    app开发,手机顶部状态栏会和app头部导航叠加在一起 解决方法:拿到顶部状态栏的高度,再给头部导航加个padding-top 在app.vue里拿到状态栏的高度并存放在globalData里 onL ...

  4. Unity 打包安卓APK到上架各大应用商店(超详细)

    一.Unity下载 1.Unity官网下载Hub,中国官网,国际版官网 2.下载Hub,安装---安装 (建议安装LTS版本) 3.添加Android 打包环境,现在新版本直接下载这个就可以直接打包了 ...

  5. Unity打包安卓如何存储本地游戏数据?

    一.前言 平时项目得数据文件文件一般都使用Resources.Load或者Application.streamingAssetsPath这两中方式读取,但是项目打包成Android或IOS时这些路径获 ...

  6. unity中打包APP显示手机最顶端的状态栏

    IOS设置: playerSettings 中: statusBar Hidden 取消勾选,Default模式对应透明底部(Translucent Over Content) 安卓: Android ...

  7. 【Unity】安卓adb 手机WiFi 调试安装应用

    安装应用 在D:\2021.1.19f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools 下cmd 先用USB 连接调试  ...

  8. unity 打包安卓UI自适应

    前言 一直以来在我感觉UI自适应就是一个老大难的问题,从入这行的时候老师给我们讲UI自适应就觉得懵懵懂懂,也许是潜意识在作祟,一直感觉UI自适应挺难的,工作之后打包apk的时候也找过UI自适应的方法, ...

  9. auto.js去除手机顶部状态栏的绿色部分

    人狠话不多,直接上代码, 'ui';/** 作者:美美*///去除状态栏顶部的绿色,此方法在安卓7-10有效果,安卓11无效activity.window.addFlags(android.view. ...

最新文章

  1. TF:tensorflow框架中常用函数介绍—tf.Variable()和tf.get_variable()用法及其区别
  2. linux python3 mysql_Python3 MySQL 数据库连接 – PyMySQL 驱动
  3. 南方s730手簿说明书_最新S730手簿及3.0简易操作82
  4. Java中的Memento设计模式-示例教程
  5. 前端学习(1802):前端调试之事件伪类练习
  6. 【Java 多线程】互斥锁,自旋锁和读写锁
  7. bzoj4415 [Shoi2013]发牌 线段树
  8. 用python生成多个txt文件
  9. 已知起点坐标、角度、长度求终点坐标
  10. Spring boot 集成mybatis 教程
  11. HTML5响应式手机模板:MUI手机app前端页面开发框架模板HTML+CSS+JavaScript
  12. 第一章 计算流体力学动力学基础知识
  13. 如何快速设计一款万能遥控器产品原型(SoC免开发)
  14. 河南省第二届“金盾信安杯”网络安全大赛 WriteUp Crypto+Misc
  15. 软件生命周期模型优缺点及适用范围
  16. Hive——多行转一行及一行转多行
  17. strlen函数原理
  18. Swarm and shipyard
  19. 手机端分页 php,网站开发-php开发手机论坛(9)-分页显示评论
  20. 从零开始Tableau | 12.表计算-特定维度

热门文章

  1. 正数的原码,反码,补码
  2. TOPSIS算法(优劣解距离法)的使用举例与matlab实现
  3. 电脑安装虚拟机网络适配器上面没有虚拟机的网络
  4. 新型冠状病毒肺炎分析
  5. java解压在线tgz文件
  6. MSXML2.DOMDocument
  7. XML(3)XDocument与XmlDocument递归读取xml文件
  8. python 获取csv的列数_《极限挑战》弹幕及评论情感分析(Python)
  9. 云计算,社交网络,移动互联网
  10. JVM和Java体系架构