Android4.4 新增沉浸模式

	public void setFullScreen()
	{
		
		//开启全屏
		View m_DecorView=getWindow().getDecorView();
		if(getSystemVersion()>18)
		{
			m_DecorView.setSystemUiVisibility(
					View.SYSTEM_UI_FLAG_LAYOUT_STABLE
					| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
					| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
					| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
					| View.SYSTEM_UI_FLAG_FULLSCREEN
					| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
					);
		}
	}


在程序onCreate() onResume() dispatchKeyEvent() onWindowFocusChanged() 分别调用


按音量键会调出按钮栏,对音量按键进行处理再次调用

	public void onWindowFocusChanged(boolean hasFocus)
	{
		Log.i("cp", "onWindowFocusChanged");
		setFullScreen();
		super.onWindowFocusChanged(hasFocus);
		mUnityPlayer.windowFocusChanged(hasFocus);

	}

	public boolean dispatchKeyEvent(KeyEvent event)
	{
		Log.i("cp", "dispatchKeyEvent");
		setFullScreen();
		if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
			return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event);
		return super.dispatchKeyEvent(event);
	}

获取系统版本

	public static int getSystemVersion()
	{
		int ver=android.os.Build.VERSION.SDK_INT;
		return ver;
	}


你可能感兴趣的:(Android4.4 新增沉浸模式)