参考 :
http://blog.csdn.net/liang_704959721/article/details/51377450
在用untiy开发应用时候发现一个问题,有几款手机有工具栏,不能实现全屏,
![](https://img-blog.csdn.net/20160511191231455?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
这个手机截图就是有工具栏的华为手机,我们怎么才能在自己的app中实现全屏。
用如下代码,拖到启动后的第一个场景的gameobject中即可:
- public class HideAndroidButtons : MonoBehaviour
- {
- #if UNITY_ANDROID && !UNITY_EDITOR
- const int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;
- const int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;
- const int SYSTEM_UI_FLAG_FULLSCREEN = 4;
-
- AndroidJavaObject decorView;
-
- void Start()
- {
- AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity");
- AndroidJavaObject window = activity.Call<AndroidJavaObject>("getWindow");
- decorView = window.Call<AndroidJavaObject>("getDecorView");
-
- TurnImmersiveModeOn();
- }
- void OnApplicationFocus(bool focusStatus) {
- if(focusStatus){
- TurnImmersiveModeOn();
- }
- }
- void TurnImmersiveModeOn()
- {
- decorView.Call("setSystemUiVisibility", SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- }
- void OnDestroy()
- {
- decorView.Dispose();
- }
- #endif
- }
![](https://img-blog.csdn.net/20160511191945686?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
全屏效果
![](https://img-blog.csdn.net/20160511192305593?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)