`
zhy20045923
  • 浏览: 153369 次
  • 性别: 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命令控制安卓手机(虚拟按键、状态栏)显示隐藏,或者直接禁用。

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

    虚拟导航栏隐藏功能patch

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

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

    Android 接口

    Android判断NavigationBar是否显示的方法(获取屏幕真实的高度)

    有些时候,我们需要知道当前手机上是否显示了NavigationBar,也就是屏幕底部的虚拟按键。 比如截屏的时候,要获取屏幕的高度,必须包括NavigationBar的高度。 试过网上的多种方法,但是对那种可以通过手势来显示/...

    0001-Android-Settings-displaySettings_RK3288_

    rk3288 隐藏状态栏和虚拟按键的补丁

    Android UI体验之全屏沉浸式透明状态栏样式

     Android 4.4之后谷歌提供了沉浸式全屏体验, 在沉浸式全屏模式下, 状态栏、 虚拟按键动态隐藏, 应用可以使用完整的屏幕空间, 按照 Google 的说法, 给用户一种 身临其境 的体验。而Android 5.0之后谷歌又提出了...

    LianDiqcj.zip

    应用开机启动,隐藏导航栏和下方虚拟按键,退出时需要输密确认才能退出应用。app 霸屏模式 和app 防卸载功能app。该资源简单有效,请放心下载

    WPF编程宝典 part2

    2.2.2 代码隐藏类 22 2.3 XAML中的属性和事件 24 2.3.1 简单属性与类型转换器 25 2.3.2 复杂属性 26 2.3.3 标记扩展 28 2.3.4 附加属性 29 2.3.5 嵌套元素 30 2.3.6 特殊字符与空白 32 2.3.7 事件 34 2.3.8 完整的...

    CalculationTest.rar

    这是一个安卓端的口算题卡项目源代码,可以实现以下功能 ①加减乘除四则运算; ②隐藏导航栏和虚拟按键; ③设置计算难度; ④保存和清空最高纪录; ⑤计算错误时出现正确答案提示;

    delphi 开发经验技巧宝典源码

    0042 如何继承父类的方法 27 0043 如何实现函数重载 28 0044 类中多态的应用 28 0045 将函数作为参数进行调用 30 2.3 参数与指针 30 0046 通过指针读写数据 30 0047 在过程中使用常量参数 31 0048 在...

    delphi 开发经验技巧宝典源码06

    0042 如何继承父类的方法 27 0043 如何实现函数重载 28 0044 类中多态的应用 28 0045 将函数作为参数进行调用 30 2.3 参数与指针 30 0046 通过指针读写数据 30 0047 在过程中使用常量参数 31 0048 在...

    AutoPlay_Menu_Builder6.0.1328注册版

     不在任务栏显示在任务栏中隐藏菜单程序。  使用系统信息框弹出信息时,使用系统默认的信息框,而不使用程序提供的 Office 风格的信息框。  窗口菜单中隐藏“关于”项隐藏菜单窗口系统菜单中的关于菜单项。  ...

    AutoPlay_Menu_Builder5.5.0.1328注册版

     不在任务栏显示在任务栏中隐藏菜单程序。  使用系统信息框弹出信息时,使用系统默认的信息框,而不使用程序提供的 Office 风格的信息框。  窗口菜单中隐藏“关于”项隐藏菜单窗口系统菜单中的关于菜单项。  ...

    WPF编程宝典 part1

    2.2.2 代码隐藏类 22 2.3 XAML中的属性和事件 24 2.3.1 简单属性与类型转换器 25 2.3.2 复杂属性 26 2.3.3 标记扩展 28 2.3.4 附加属性 29 2.3.5 嵌套元素 30 2.3.6 特殊字符与空白 32 2.3.7 事件 34 2.3.8 完整的...

    新版Android开发教程.rar

    程序可以采用 JAVA 开发,但是因为它的虚拟机 (Virtual Machine) Dalvik ,是将 JAVA 的 bytecode 转成 自 己的格式,回避掉需要付给 SUN 有关 JAVA 的授权费用。 对手机制造者的影响 � Android 是款开源的移动计算...

Global site tag (gtag.js) - Google Analytics