AndroidのUI体验之ImmersiveMode沉浸模式
4.4带来了新的api——ImmersiveMode,可以使用户进入沉浸模式,享受更好的用户体验。
打开沉浸模式:
/**
* Detects and toggles immersive mode (also known as "hidey bar" mode).
*/
public void toggleHideyBar() { // BEGIN_INCLUDE (get_current_ui_flags)
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
// END_INCLUDE (get_current_ui_flags)
// BEGIN_INCLUDE (toggle_ui_flags)
boolean isImmersiveModeEnabled =
((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.i(TAG, "Turning immersive mode mode off. ");
} else {
Log.i(TAG, "Turning immersive mode mode on.");
} // Navigation bar hiding: Backwards compatible to ICS.
if (Build.VERSION.SDK_INT >= 14) {
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
} // Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
} // Immersive mode: Backward compatible to KitKat.
// Note that this flag doesn't do anything by itself, it only augments the behavior
// of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample
// all three flags are being toggled together.
// Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
// Sticky immersive mode differs in that it makes the navigation and status bars
// semi-transparent, and the UI flag does not get cleared when the user interacts with
// the screen.
if (Build.VERSION.SDK_INT >= 18) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
} getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
//END_INCLUDE (set_ui_flags)
}
而这个状态发生变化可以显示这个监听器:
final View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int i) {
int height = decorView.getHeight();
Log.i(TAG, "Current height: " + height);
}
});
总共有5中Flag作用都不相同
// BEGIN_INCLUDE (get_current_ui_flags)
// The "Decor View" is the parent view of the Activity. It's also conveniently the easiest
// one to find from within a fragment, since there's a handy helper method to pull it, and
// we don't have to bother with picking a view somewhere deeper in the hierarchy and calling
// "findViewById" on it.
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = decorView.getSystemUiVisibility();
int newUiOptions = uiOptions;
// END_INCLUDE (get_current_ui_flags) // BEGIN_INCLUDE (toggle_lowprofile_mode)
// Low profile mode doesn't resize the screen at all, but it covers the nav & status bar
// icons with black so they're less distracting. Unlike "full screen" and "hide nav bar,"
// this mode doesn't interact with immersive mode at all, but it's instructive when running
// this sample to observe the differences in behavior.
if (mLowProfileCheckBox.isChecked()) {
newUiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;//低调模式:通知栏和虚拟键变暗
} else {
newUiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
}
// END_INCLUDE (toggle_lowprofile_mode) // BEGIN_INCLUDE (toggle_fullscreen_mode)
// When enabled, this flag hides non-critical UI, such as the status bar,
// which usually shows notification icons, battery life, etc
// on phone-sized devices. The bar reappears when the user swipes it down. When immersive
// mode is also enabled, the app-drawable area expands, and when the status bar is swiped
// down, it appears semi-transparently and slides in over the app, instead of pushing it
// down.
if (mHideStatusBarCheckBox.isChecked()) {//全屏模式:隐藏状态栏,但并不隐藏虚拟键
newUiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
} else {
newUiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
}
// END_INCLUDE (toggle_fullscreen_mode) // BEGIN_INCLUDE (toggle_hidenav_mode)
// When enabled, this flag hides the black nav bar along the bottom,
// where the home/back buttons are. The nav bar normally instantly reappears
// when the user touches the screen. When immersive mode is also enabled, the nav bar
// stays hidden until the user swipes it back.
if (mHideNavCheckbox.isChecked()) {//隐藏虚拟键,点击可出现
newUiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
} else {
newUiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
// END_INCLUDE (toggle_hidenav_mode) // BEGIN_INCLUDE (toggle_immersive_mode)
// Immersive mode doesn't do anything without at least one of the previous flags
// enabled. When enabled, it allows the user to swipe the status and/or nav bars
// off-screen. When the user swipes the bars back onto the screen, the flags are cleared
// and immersive mode is automatically disabled.
if (mImmersiveModeCheckBox.isChecked()) {
newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
} else {
newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE;
}
// END_INCLUDE (toggle_immersive_mode) // BEGIN_INCLUDE (toggle_immersive_mode_sticky)
// There's actually two forms of immersive mode, normal and "sticky". Sticky immersive mode
// is different in 2 key ways:
//
// * Uses semi-transparent bars for the nav and status bars
// * This UI flag will *not* be cleared when the user interacts with the UI.
// When the user swipes, the bars will temporarily appear for a few seconds and then
// disappear again.
if (mImmersiveModeStickyCheckBox.isChecked()) {
newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
} else {
newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
// END_INCLUDE (toggle_immersive_mode_sticky) // BEGIN_INCLUDE (set_ui_flags)
//Set the new UI flags.
decorView.setSystemUiVisibility(newUiOptions);
Log.i(TAG, "Current height: " + decorView.getHeight() + ", width: " + decorView.getWidth());
// END_INCLUDE (set_ui_flags)
附件貌似传不了啊
AndroidのUI体验之ImmersiveMode沉浸模式的更多相关文章
- Android UI体验之全屏沉浸式透明状态栏效果
前言: Android 4.4之后谷歌提供了沉浸式全屏体验, 在沉浸式全屏模式下, 状态栏. 虚拟按键动态隐藏, 应用可以使用完整的屏幕空间, 按照 Google 的说法, 给用户一种 身临其境 的体 ...
- Android UI--提高Android UI体验
1,自定义虚拟键盘 当一个用户被要求在一个文本框输入时希望又怎样的体验? 从用户需求来看,虚拟键盘应该改变以帮助用户输入的数据.这里是一些例子: 如果一个视图是一个电子邮件地址,一个键盘的“@”符号 ...
- AndroidのUI体验之上拉下拉
1.ScrollView监测是否滚动到顶部或底部 onScrollChanged(); 滚动到顶部判断:getScrollY() == 0 滚动到底部判断:getChildAt(0).getMeasu ...
- Android Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏)
Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏) [科普]什么叫真正的“沉浸式”状态栏? 为什么在国内会有很多用户把「透明栏」(Translucent ...
- [Android] 关于系统工具栏和全屏沉浸模式
随着应用程序的一些深入设计,大家总想要更好的界面和体验,所以有些东西并不能只是知道方法就结束了,是得要去深入研究研究的.通过这个过程我觉得,从应用层面来讲,想实现一个功能很简单,但若想实现的好,就要去 ...
- GitHub上受欢迎的Android UI Library
GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...
- Android UI相关开源项目库汇总
最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- 详解 “Android UI”设计官方教程
我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...
随机推荐
- C#开发实例 键盘篇
键盘的操作控制: 键盘和鼠标一样是重要输入设备的一部分.开发过程中,会涉及到很多的键盘操作控制. 2.1获取键盘信息 ①获取组合键 Windows中有很多默认的组合键,如Ctrl+v,Ctrl+A.本 ...
- sizeof()和strlen()的区别与联系
参考:http://www.cnblogs.com/carekee/articles/1630789.html 1.sizeof是运算符,其值在编译时即计算好了,参数可以是数组.指针.类型.对象.函数 ...
- 详解HttpURLConnection
请求响应流程 设置连接参数的方法 setAllowUserInteraction setDoInput setDoOutput setIfModifiedSince setUseCaches setD ...
- 【Docker】来自官方映像的 6 个 Dockerfile 技巧
本文将根据我从官方镜像学到的经验,讲解编写Dockerfile的技巧. 1. 选择Debian 官方镜像的大多数Dockerfile,不管是直接还是通过其他镜像,都是基于Debian的.Dock ...
- linux中pip安装步骤与使用详解
pip类似RedHat里面的yum,安装软件非常方便.本节详细介绍pip的安装.以及使用方法,希望文章对各位了解pip的安装与使用带来帮助. 1.pip下载安装1.1 pip下载 代码如下 复制代码 ...
- 【python】choice函数
来源:http://www.runoob.com/python/func-number-choice.html 描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choi ...
- 【linux】VMware12.0安装
问题1:安装虚拟机时出现The Microsoft Runtime DLL installer failed to complete 解决: 重新安装,安装失败时不要点击结束,在开始“运行”出输入%t ...
- 说说localStorage
HTML5的本地存储是大势所趋,如果仅存储在内存中,则是sessionStorage,他们的语法都是一样,仅仅是一个存储在本地文件系统中,另一个存储在内存中(随着浏览器的关闭而消失),其语句如下: l ...
- 学习BigDecimal用法
一.简介 Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算.双精度浮点型变量double可以处理16位有效数.在实际应用中,需要对更大或者更 ...
- /bin/dd if=/path/to/source-file of=/path/to/backup-file
[root@ok virhost]# qemu-img info 05t.img image: 05t.img file format: raw virtual size: 10G (10737418 ...