如何在Android活动中永久隐藏导航栏?

我想在我的活动中永久隐藏导航栏(而不是整个系统ui)。现在我正在使用这段代码


getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

它隐藏了该条,但是当用户触摸屏幕时它再次显示。有什么方法可以永久隐藏它,直到活动结束onStop();


BIG阳
浏览 1438回答 3
3回答

繁星coding

做这个。public void FullScreencall() {&nbsp; &nbsp; if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api&nbsp; &nbsp; &nbsp; &nbsp; View v = this.getWindow().getDecorView();&nbsp; &nbsp; &nbsp; &nbsp; v.setSystemUiVisibility(View.GONE);&nbsp; &nbsp; } else if(Build.VERSION.SDK_INT >= 19) {&nbsp; &nbsp; &nbsp; &nbsp; //for new api versions.&nbsp; &nbsp; &nbsp; &nbsp; View decorView = getWindow().getDecorView();&nbsp; &nbsp; &nbsp; &nbsp; int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;&nbsp; &nbsp; &nbsp; &nbsp; decorView.setSystemUiVisibility(uiOptions);&nbsp; &nbsp; }}这可以100%起作用,并且即使API的版本太晚,您也可以对较低的API版本执行相同的操作,我希望它将对其他人有所帮助。如果您希望这是永久的,只需FullscreenCall()在您的onResume()方法内部调用。

翻阅古今

根据Android开发者网站我认为您不能(据我所知)永久隐藏导航栏。但是,您可以做一招。这是一个技巧。只是当navigation bar用户触摸屏幕时出现。立即将其再次隐藏。很有趣。检查一下。void setNavVisibility(boolean visible) {int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN&nbsp; &nbsp; &nbsp; &nbsp; | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION&nbsp; &nbsp; &nbsp; &nbsp; | SYSTEM_UI_FLAG_LAYOUT_STABLE;if (!visible) {&nbsp; &nbsp; newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | SYSTEM_UI_FLAG_HIDE_NAVIGATION;}// If we are now visible, schedule a timer for us to go invisible.if (visible) {&nbsp; &nbsp; Handler h = getHandler();&nbsp; &nbsp; if (h != null) {&nbsp; &nbsp; &nbsp; &nbsp; h.removeCallbacks(mNavHider);&nbsp; &nbsp; &nbsp; &nbsp; if (!mMenusOpen && !mPaused) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If the menus are open or play is paused, we will not auto-hide.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h.postDelayed(mNavHider, 1500);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}// Set the new desired visibility.setSystemUiVisibility(newVis);mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE);mPlayButton.setVisibility(visible ? VISIBLE : INVISIBLE);mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android