private void hideSystemUI() {
View decorView = getWindow().getDecorView();
int uiOptions = 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;
decorView.setSystemUiVisibility(uiOptions);
}
还有:
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(
newView.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int i) {
if (i == View.VISIBLE){
hideSystemUI();
}
else {
hideSystemUI();
}
}
});
在onCreate()和onResume()中编写了hidesystemUI()代码,包括 decorView.setOnSystemUiVisibilityChangeListener()。所以我必须阻止它。一旦我在顶部滑动,它就会回来(像眨眼一样)。但我必须阻止它。一旦我们在顶部滑动它就不会出现。帮助我解决这个问题。
答案 0 :(得分:0)
如果你不想让它眨眼,你可能会延迟隐藏。例如,您可以按Handler.postDelayed()
延迟2秒。
private void hideSystemUI() {
final int uiOptions = 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;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getWindow().getDecorView().setSystemUiVisibility(uiOptions);
}
}, 2000); //2 seconds delay
}
如果你总是在主线程上调用它,你可以简单地调用new Handler()
来返回主线程上的Handler。否则,您需要致电new Handler(Looper.getMainLooper())
。