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沉浸模式的更多相关文章

  1. Android UI体验之全屏沉浸式透明状态栏效果

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

  2. Android UI--提高Android UI体验

    1,自定义虚拟键盘 当一个用户被要求在一个文本框输入时希望又怎样的体验?  从用户需求来看,虚拟键盘应该改变以帮助用户输入的数据.这里是一些例子: 如果一个视图是一个电子邮件地址,一个键盘的“@”符号 ...

  3. AndroidのUI体验之上拉下拉

    1.ScrollView监测是否滚动到顶部或底部 onScrollChanged(); 滚动到顶部判断:getScrollY() == 0 滚动到底部判断:getChildAt(0).getMeasu ...

  4. Android Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏)

    Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏) [科普]什么叫真正的“沉浸式”状态栏? 为什么在国内会有很多用户把「透明栏」(Translucent ...

  5. [Android] 关于系统工具栏和全屏沉浸模式

    随着应用程序的一些深入设计,大家总想要更好的界面和体验,所以有些东西并不能只是知道方法就结束了,是得要去深入研究研究的.通过这个过程我觉得,从应用层面来讲,想实现一个功能很简单,但若想实现的好,就要去 ...

  6. GitHub上受欢迎的Android UI Library

    GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...

  7. Android UI相关开源项目库汇总

    最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...

  8. 各种Android UI开源框架 开源库

    各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...

  9. 详解 “Android UI”设计官方教程

    我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...

随机推荐

  1. win7 64位系统HP LaserJet P1008 / HP LaserJet P1008 P1007 驱动安装成功,但无法打印的原因

    HP LaserJet P1008 打印机驱动安装成功,但是无法打印相关文档的原因是: 1.打印机是水货,惠普中国提供的驱动和该打印机不符合.显示的应该是HP LaserJet Professiona ...

  2. codeforces A. Puzzles 解题报告

    题目链接:http://codeforces.com/problemset/problem/337/A 题意:有n个学生,m块puzzles,选出n块puzzles,但是需要满足这n块puzzles里 ...

  3. ORACLE恢复删除的数据

    ---正在执行的 select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT  from v$session a, v$sqlarea b where a. ...

  4. JsRender语法

    {{:#data.Name}} 或 {{:Name}} 直接显示html格式{{>#data.Name}} 或 {{>Name}} 转义显示html字符 if else {{if bool ...

  5. [Android Pro] 监听Blutooth打开广播

    <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission a ...

  6. C++里的静态成员函数不能用const的原因

    From http://blog.csdn.net/freeboy1015/article/details/7634950     static在c++中的第五种含义:用static修饰不访问非静态数 ...

  7. Android之Intent深入

    Android中的意图包含多种用法,本文主要包括以下内容 显式意图 隐匿意图 要求结果回传的意图 显式意图 :必须指定要激活的组件的完整包名和类名 (应用程序之间耦合在一起) 一般激活自己应用的组件的 ...

  8. obj-m

    转自:http://blog.sina.com.cn/s/blog_693301190100sxoi.html obj-m (转帖) 目标定义是Kbuild Makefile的主要部分,也是核心部分. ...

  9. 百万用户时尚分享网站feed系统扩展实践

    Fashiolista是一个在线的时尚交流网站,用户可以在上面建立自己的档案,和他人分享自己的以及在浏览网页时看到的时尚物品.目前,Fashiolista的用户来自于全球100多个国家,用户达百万级, ...

  10. SQLServer中临时表与表变量的区别分析(转)

    在实际使用的时候,我们如何灵活的在存储过程中运用它们,虽然它们实现的功能基本上是一样的,可如何在一个存储过程中有时候去使用临时表而不使用表变量,有时候去使用表变量而不使用临时表呢? 临时表 临时表与永 ...