01.
private
int
currentApiVersion;
02.
03.
@Override
04.
@SuppressLint
(
"NewApi"
)
05.
protected
void
onCreate(Bundle savedInstanceState)
06.
{
07.
super
.onCreate(savedInstanceState);
08.
09.
currentApiVersion = android.os.Build.VERSION.SDK_INT;
10.
11.
final
int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
12.
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
13.
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
14.
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
15.
| View.SYSTEM_UI_FLAG_FULLSCREEN
16.
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
17.
18.
19.
if
(currentApiVersion >= Build.VERSION_CODES.KITKAT)
20.
{
21.
22.
getWindow().getDecorView().setSystemUiVisibility(flags);
23.
24.
25.
26.
27.
final
View decorView = getWindow().getDecorView();
28.
decorView
29.
.setOnSystemUiVisibilityChangeListener(
new
View.OnSystemUiVisibilityChangeListener()
30.
{
31.
32.
@Override
33.
public
void
onSystemUiVisibilityChange(
int
visibility)
34.
{
35.
if
((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) ==
0
)
36.
{
37.
decorView.setSystemUiVisibility(flags);
38.
}
39.
}
40.
});
41.
}
42.
43.
}
44.
45.
46.
@SuppressLint
(
"NewApi"
)
47.
@Override
48.
public
void
onWindowFocusChanged(
boolean
hasFocus)
49.
{
50.
super
.onWindowFocusChanged(hasFocus);
51.
if
(currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
52.
{
53.
getWindow().getDecorView().setSystemUiVisibility(
54.
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
55.
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
56.
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
57.
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
58.
| View.SYSTEM_UI_FLAG_FULLSCREEN
59.
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
60.
}
61.
}