package com.my.fullscreen;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener {
View main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
main = getLayoutInflater().inflate(R.layout.activity_main, null);
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
main.setOnClickListener(this);
setContentView(main);
}
@Override
public void onClick(View v) {
int i = main.getSystemUiVisibility();
if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {//2
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
} else if (i == View.SYSTEM_UI_FLAG_VISIBLE) {//0
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
} else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {//1
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
}
此时该Activity显示时会自动隐藏Navigation Bar,但有触摸事件时重新显现Navigation Bar。屏幕的Layout会自动收缩适应新的屏幕大小。
1)View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
2)View.SYSTEM_UI_FLAG_IMMERSIVE
同时设置以上两个参数,即使Touch Screen时,Navigation bar也不会显示出来。
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE);