在活动中永久隐藏导航栏
是否有可能永久删除一个活动的导航栏? 我想要使用平板电脑屏幕上的button而不是操作栏上的button来移除条形图。 这里
我知道不build议这样做,我没有做出这个决定,但我需要这样做。 在我的布局,有另一个button来离开活动。 我的应用程序的其余部分可以有,并有导航栏。
我发现这个代码,并适应了它一点点。 问题是,即使隐藏导航栏,也留下了黑色的空间。 我猜系统会计算导航栏的屏幕大小?
public static class Content extends ImageView implements View.OnSystemUiVisibilityChangeListener, View.OnClickListener, ActionBar.OnMenuVisibilityListener { Activity mActivity; TextView mTitleView; Button mPlayButton; SeekBar mSeekView; boolean mAddedMenuListener; boolean mMenusOpen; boolean mPaused; boolean mNavVisible; int mLastSystemUiVis; Runnable mNavHider = new Runnable() { @Override public void run() { setNavVisibility(false); } }; public Content(Context context, AttributeSet attrs) { super(context, attrs); setOnSystemUiVisibilityChangeListener(this); setOnClickListener(this); } public void init(Activity activity, TextView title, Button playButton, SeekBar seek) { // This called by the containing activity to supply the surrounding // state of the video player that it will interact with. mActivity = activity; mTitleView = title; mPlayButton = playButton; mSeekView = seek; mPlayButton.setOnClickListener(this); setPlayPaused(true); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mActivity != null) { mAddedMenuListener = true; mActivity.getActionBar().addOnMenuVisibilityListener(this); } } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAddedMenuListener) { mActivity.getActionBar().removeOnMenuVisibilityListener(this); } } @Override public void onSystemUiVisibilityChange(int visibility) { // Detect when we go out of nav-hidden mode, to clear our state // back to having the full UI chrome up. Only do this when // the state is changing and nav is no longer hidden. int diff = mLastSystemUiVis ^ visibility; mLastSystemUiVis = visibility; if ((diff&SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 && (visibility&SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { setNavVisibility(true); } } @Override protected void onWindowVisibilityChanged(int visibility) { super.onWindowVisibilityChanged(visibility); // When we become visible or invisible, play is paused. setPlayPaused(true); } @Override public void onClick(View v) { if (v == mPlayButton) { // Clicking on the play/pause button toggles its state. setPlayPaused(!mPaused); } else { // Clicking elsewhere makes the navigation visible. setNavVisibility(true); } } @Override public void onMenuVisibilityChanged(boolean isVisible) { mMenusOpen = isVisible; setNavVisibility(true); } void setPlayPaused(boolean paused) { mPaused = paused; mPlayButton.setText(paused ? R.string.play : R.string.pause); setKeepScreenOn(!paused); setNavVisibility(true); } void setNavVisibility(boolean visible) { int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_STABLE; if (!visible) { newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // If we are now visible, schedule a timer for us to go invisible. if (visible) { Handler h = getHandler(); if (h != null) { h.removeCallbacks(mNavHider); if (!mMenusOpen && !mPaused) { // If the menus are open or play is paused, we will not auto-hide. h.postDelayed(mNavHider, 1500); } } } // Set the new desired visibility. setSystemUiVisibility(newVis); mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE); mPlayButton.setVisibility(visible ? VISIBLE : INVISIBLE); mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE); } }
AFAIK,这是不可能的,没有根访问权限。 这将是一个安全问题,能够有一个应用程序不能退出系统button。
编辑,看到这里: 隐藏平板电脑中的系统栏
有一个从KitKat(4.4.2)开始的解决scheme,称为沉浸模式: https : //developer.android.com/training/system-ui/immersive.html
基本上,你应该添加这个代码到你的onResume()方法:
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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
您可以
有两种方法:
1-根您的设备,然后在adb window command
打开设备,然后运行以下adb window command
:
adb shell > su > pm disable com.android.systemui >
并取回它只是做同样的事情,但更改disable
enable
。
2-将以下行添加到设备的build.prop文件的末尾:
qemu.hw.mainkeys = 1
然后把它拿回来只是删除它。
如果你不知道如何编辑build.prop文件:
- 在你的设备上下载EsExplorer并searchbuild.prop,然后改变它的读写权限,最后添加该行。
- 下载一个专门的build.prop编辑器应用程序,如build.propEditor 。
- 或参考该链接 。
你可以隐藏导航栏,只需在你的onCreate()
方法上调用这个方法,
public void FullScreencall() { if(Build.VERSION.SDK_INT < 19){ View v = this.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else { //for higher api versions. View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; decorView.setSystemUiVisibility(uiOptions); } }
这将隐藏整个协调panel.hope它可以帮助你
更改清单中的主题。
如果你想隐藏一个活动的导航栏,你可以使用这个:
<activity android:name="Activity Name" android:theme="@android:style/Theme.Black.NoTitleBar" android:label="@string/app_name" >
如果你想隐藏整个应用程序的导航栏,你可以使用这个:
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar" >
首先隐藏在Activity的OnResume()中,然后继续隐藏,如下所示:
decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { // Note that system bars will only be "visible" if none of the // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { //visible hideSystemUI(); } } } });` public 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. 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); }
在观看DevBytes video (由Roman Nurik撰写)并阅读文档中的最后一行之后,其中说:
注意:如果您喜欢IMMERSIVE_STICKY的自动隐藏行为,但也需要显示自己的UI控件,只需使用IMMERSIVE与Handler.postDelayed()或类似的东西,几秒钟后重新进入沉浸式模式。
radu122给的答案,为我工作。 只要设置一个处理程序,你会很好去。
这里是适合我的代码:
@Override protected void onResume() { super.onResume(); executeDelayed(); } private void executeDelayed() { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // execute after 500ms hideNavBar(); } }, 500); } private void hideNavBar() { if (Build.VERSION.SDK_INT >= 19) { View v = getWindow().getDecorView(); v.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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }
谷歌说“几秒钟后” – 但我想尽快提供这个function。 也许我会改变价值,如果我必须,我会更新这个答案。
来自Google文档:
您可以使用SYSTEM_UI_FLAG_HIDE_NAVIGATION标志在Android 4.0及更高版本上隐藏导航栏。 这段代码隐藏了导航栏和状态栏:
View decorView = getWindow().getDecorView(); // Hide both the navigation bar and the status bar. // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as // a general rule, you should design your app to hide the status bar whenever you // hide the navigation bar. int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions);
http://developer.android.com/training/system-ui/navigation.html
我的解决scheme,只隐藏导航栏,是:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } }); } @Override protected void onResume() { super.onResume(); final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; final View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(uiOptions); }