我想知道如何在用户点按屏幕时隐藏来自 Android 的Status Bar
,Navigation Bar
和Toolbar
,如QuickPick应用中所示:< / p>
我已经做了很多研究,但我找不到或猜测如何实现这种行为,有人可以解释一种方法吗?
答案 0 :(得分:0)
这是我的解决方案:
button.setOnClickListener(new View.OnClickListener() {
boolean show = true;
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "CLICK", Toast.LENGTH_SHORT).show();
if (show) {
toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
hideSystemUI();
show = false;
} else {
toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
showSystemUI();
show = true;
}
}
});
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
View decorView = getWindow().getDecorView();
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
private void showSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
.....................
不要忘记在主视图中将fitsSystemWindows设置为true