`
zhy20045923
  • 浏览: 157027 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

[转]隐藏虚拟按键(导航栏)的方法

阅读更多
Controls for system UI visibility

Since the early days of Android, the system has managed a UI component known as the status bar, which resides at the top of handset devices to deliver information such as the carrier signal, time, notifications, and so on. Android 3.0 added the system bar for tablet devices, which resides at the bottom of the screen to provide system navigation controls (Home, Back, and so forth) and also an interface for elements traditionally provided by the status bar. In Android 4.0, the system provides a new type of system UI called the navigation bar. You might consider the navigation bar a re-tuned version of the system bar designed for handsets—it provides navigation controls for devices that don’t have hardware counterparts for navigating the system, but it leaves out the system bar's notification UI and setting controls. As such, a device that provides the navigation bar also has the status bar at the top.

To this day, you can hide the status bar on handsets using the FLAG_FULLSCREEN flag. In Android 4.0, the APIs that control the system bar’s visibility have been updated to better reflect the behavior of both the system bar and navigation bar:

    The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.
    The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.
    The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required.

You can set each of these flags for the system bar and navigation bar by calling setSystemUiVisibility() on any view in your activity. The window manager combines (OR-together) all flags from all views in your window and apply them to the system UI as long as your window has input focus. When your window loses input focus (the user navigates away from your app, or a dialog appears), your flags cease to have effect. Similarly, if you remove those views from the view hierarchy their flags no longer apply.

To synchronize other events in your activity with visibility changes to the system UI (for example, hide the action bar or other UI controls when the system UI hides), you should register a View.OnSystemUiVisibilityChangeListener to be notified when the visibility of the system bar or navigation bar changes.

See the OverscanActivity class for a demonstration of different system UI options.

控制导航栏的显示有两种修改方法:
1.临时修改,通过方法mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)方法设置。注意该方法必须放在setContentView(mView)之前,具体代码如下:
public class HideTestActivity extends Activity implements OnClickListener{
	View main ;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        main = getLayoutInflater().from(this).inflate(R.layout.main, null);
        main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        main.setOnClickListener(this);
        setContentView(main);
    }

	@Override
	public void onClick(View v) {
		int i = main.getSystemUiVisibility();
		if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
		} else if (i == View.SYSTEM_UI_FLAG_VISIBLE){
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
		} else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
		}
	}
}

2.永久隐藏法。修改系统文件/framework/base/core/res/res/values/config.xml的变量config_showNavigationBar值。如果不起作用,那就是该值被android.content.res.Configuration类的变量navigationHidden所取代,需要修改此值(搜索SystemUI得知,显示导航栏与否是通过方法mWindowManagerService.hasNavigationBar()判断的,该方法的实现是在PhoneWindowManager类里面mHasNavigationBar设置的。)
分享到:
评论

相关推荐

    0001-导航栏添加按钮隐藏虚拟按键,上滑调出虚拟按键.patch

    0001-导航栏添加按钮隐藏虚拟按键,上滑调出虚拟按键

    ADB命令控制安卓手机(虚拟按键、状态栏)显示隐藏,或者直接禁用。

    4. 隐藏虚拟按键:虚拟按键,也称为导航栏,包括返回、主页和多任务按钮。使用以下命令可以隐藏虚拟按键: ``` adb shell input keyevent 82 ``` 这个命令模拟按下菜单键,从而隐藏虚拟按键。若要重新显示,...

    添加虚拟按键隐藏控制

    调用`getWindow().getDecorView()`获取到当前Activity的装饰视图,然后调用`setSystemUiVisibility()`方法,传入`View.SYSTEM_UI_FLAG_HIDE_NAVIGATION`标志来隐藏虚拟按键。 ```java // 隐藏虚拟按键 decorView....

    GMD自动隐藏虚拟按键专业版.zip

    【GMD自动隐藏虚拟按键专业版】是一款专为Android设备设计的应用程序,旨在提供更加纯净、无干扰的屏幕体验。该应用的主要功能是隐藏设备底部的系统导航栏,即我们通常所说的“虚拟按键”,如返回、主页和多任务键。...

    隐藏、显示导航栏(虚拟按键)接口.txt

    ### 隐藏、显示导航栏(虚拟按键)...通过上述详细解析,我们可以了解到Android系统中隐藏和显示导航栏(虚拟按键)的具体实现方法及其背后的原理。这对于希望优化应用界面交互体验的开发者来说是非常有用的参考资料。

    Android 解决沉浸式状态栏和华为虚拟按键冲突

    在Android 4.4(KitKat)版本中引入了全屏沉浸模式,通过`SYSTEM_UI_FLAG_HIDE_NAVIGATION`和`SYSTEM_UI_FLAG_FULLSCREEN`这两个系统UI标志位,可以隐藏底部导航栏和顶部状态栏,让应用界面充满整个屏幕。...

    android 闪屏 欢迎界面 隐藏底部虚拟按钮全屏 适配方案

    - 在Activity的`onCreate()`方法中,获取到`Window`对象,并调用`setFlags()`方法,传递`SYSTEM_UI_FLAG_HIDE_NAVIGATION`标志,隐藏虚拟按键。 - 注意:隐藏后,用户可能无法快速返回主界面,因此需要监听`SYSTEM...

    安卓P 动态隐藏虚拟按键.zip

    在安卓P(Android P)系统中,动态隐藏虚拟按键是一项重要的功能优化,它允许开发者或者用户根据应用的需求或个人偏好来控制导航栏的可见性。这项功能主要涉及到系统的UI交互和自定义设置,提升了用户体验,特别是在...

    虚拟导航栏隐藏功能patch

    此功能主要添加frameworks\base\services的功能在此目录下请搜索FEATURE_AUTO_HIDE_NAVIGATIONBAR,frameworks\base\packages\SystemUI下按键添加,需要...隐藏后需要显示导航栏请从下往上滑动,此功能只针对虚拟按键

    安卓消息推送通知栏相关-去除标题去除状态栏和隐藏虚拟按键.rar

    这个压缩包文件"安卓消息推送通知栏相关-去除标题去除状态栏和隐藏虚拟按键.rar"似乎包含了一些实现特定UI效果的代码示例,主要目标是使应用在全屏模式下运行时更加沉浸式,即去除标题、状态栏以及隐藏虚拟按键。...

    android 适配底部虚拟按键

    5. **判断虚拟按键状态**:利用`DisplayMetrics`和`View`类提供的方法,可以检测当前设备是否存在底部虚拟按键,以及其尺寸。这样可以针对性地处理布局,确保在各种设备上表现一致。 6. **Jetpack Compose适配**:...

    虚拟按键对全屏视频的影响

    // 隐藏虚拟按键 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); // 再次检查 // assertNoOverlap(videoPlayer.getVideoView(), decorView.findViewById(android.R.id....

    Android实现手机游戏隐藏虚拟按键

    首先,隐藏虚拟按键主要通过调用`View`类的`setSystemUiVisibility()`方法来实现。在`MainActivity`的`onCreate()`方法中,我们可以添加以下代码: ```java @Override protected void onCreate(Bundle icicle) { ...

    Android 虚拟按键

    本文将详细介绍如何在Android开发中实现去除标题、去除状态栏以及隐藏虚拟按键的操作。 首先,我们来看如何隐藏标题。在Android应用中,标题通常是由ActionBar或者Toolbar提供的。如果你使用的是Android Studio,...

    android底层去掉虚拟按键的实例讲解

    对于普通应用,通常需要依赖API提供的方法,如在Android 4.4及以上版本中使用`SYSTEM_UI_FLAG_HIDE_NAVIGATION`或`SYSTEM_UI_FLAG_IMMERSIVE_STICKY`等标志来隐藏虚拟按键。但这种方法并不能完全去除虚拟按键,用户...

    设置沉浸式布局后,手机状态栏或导航栏出现白屏。

    - 对于需要隐藏虚拟键的设备,没有处理好硬件按键的隐藏逻辑。 - 在配置更改后(如屏幕旋转)没有重新设置沉浸式状态。 解决白屏问题的步骤可能包括: 1. **检查权限**:确保应用有正确的权限,如`android....

    Android适配底部虚拟按键的方法详解

    但是,单纯地隐藏虚拟按键可能会引发其他问题,比如手动隐藏后出现长白条区域、状态栏隐藏后虚拟按键不随之隐藏,以及在无虚拟按键设备上影响SurfaceView的全屏显示等。 在解决这些问题的过程中,关键在于正确地...

    Unity3D Android 状态栏

    例如,使用以下代码隐藏虚拟按键: ```java View decorView = UnityPlayer.currentActivity.getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; decorView....

    苹果浏览器微信底部返回栏显示/隐藏的问题

    此段js代码完美解决 ; (function () { try { isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) if (fn.isIOS) { // window.history.pushState({}, title, #);... document.addEventListener...

Global site tag (gtag.js) - Google Analytics