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++中的复制、赋值、析构
一直对C++的复制(Copy).赋值(Assign)操作比较困惑,现在看书的时候看到了,就把它顺便记下来. 一.什么时候触发 一下代码可以熟悉什么时候触发复制操作,以及什么时候触发赋值操作: // t ...
- poj2253 最短路 floyd Frogger
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28825 Accepted: 9359 Descript ...
- php如何将数组保存为文件的方法? 三个方法让你快速把数组保存成为文件存储
php 缓存数组形式的变量,实际上就是将 php 将数组写入到一个文本文件或者后缀名为 .php 存储起来,使用的时候直接调用这个文件.那么如何使用 php 将数组保存为文本格式的文件呢?下面分享三种 ...
- ios7技巧:你需要掌握的19个iOS7使用技巧
从右往左滑动屏幕,可看到信息收到的时间. 指南针应用还可以用作水平仪,滑动屏幕即可. 被苹果称作Spotlight的搜索功能有所改变.在屏幕中间向下滑动即可打开该项功能,你可以搜索文本.邮件.应用.歌 ...
- Java for LeetCode 035 Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- Fedora 21 install chrome
Steps to install Google Chrome on Fedora 21 A. Create google-chrome.repo file Use this command to cr ...
- Nginx+Keepalived主从双机热备+自动切换
1 安装配置nginx 参考: http://www.cnblogs.com/jager/p/4388202.html 2 安装配置keepalived tar xvf keepalived-1.2. ...
- 二、JavaScript语言--JS基础--JavaScript进阶篇--JS基础语法
1.变量 定义:从字面上看,变量是可变的量:从编程角度讲,变量是用于存储某种/某些数值的存储器.我们可以把变量看做一个盒子,盒子用来存放物品,物品可以是衣服.玩具.水果...等. 命名:变量名字可以任 ...
- LeetCode之Min Stack 实现最小栈
LeetCode相关的网上资源比较多,看到题目一定要自己做一遍,然后去学习参考其他的解法. 链接: https://oj.leetcode.com/problems/min-stack/ 题目描述: ...
- ubuntu下eclipse无法启动问题
添加-vm和对应参数 -vm/jdk安装目录/bin/java-startupplugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.j ...