AndroidのUI体验之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)

时间: 2024-10-15 11:09:42

AndroidのUI体验之ImmersiveMode沉浸模式的相关文章

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

前言: Android 4.4之后谷歌提供了沉浸式全屏体验, 在沉浸式全屏模式下, 状态栏. 虚拟按键动态隐藏, 应用可以使用完整的屏幕空间, 按照 Google 的说法, 给用户一种 身临其境 的体验.而Android 5.0之后谷歌又提出了 ColorPalette 的概念,让开发者可以自己设定系统区域的颜色,使整个 App 的颜色风格和系统的颜色风格保持统一.今天学习总结一下如何实现Android 4.4以上全屏沉浸式透明状态栏效果.先看下预期效果: 首先现分清楚哪部分是状态栏,哪部分是导

AndroidのUI体验之上拉下拉

1.ScrollView监测是否滚动到顶部或底部 onScrollChanged(); 滚动到顶部判断:getScrollY() == 0 滚动到底部判断:getChildAt(0).getMeasuredHeight() <= getScrollY() + getHeight() 当getScrollY()达到最大时加上scrollView的高度就的就等于它内容的高度 2.ListView.GridView(AbListView)滚动到最后一条监听 onScrollStateChanged()

Android 沉浸模式

---恢复内容开始--- 当Android系统版本大于19(4.4),就可以开启沉浸式标题栏: 可以将其封装成方法进行调用. 1 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 2 Window win = getWindow(); 3 4 WindowManager.LayoutParams winParams = win.getAttributes(); 5 winParams.flags |= WindowManager

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

关于System Bars,之前写过几篇相关的文章: [Android]获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度 [Android]状态栏的一些认识 [Android]锁定屏幕 这三篇是按顺序写的,本来只是项目上的应用,其实并不需要深究的,查到方法并能用起来就好.随着应用程序的一些深入设计,大家总想要更好的界面和体验,所以有些东西并不能只是知道方法就结束了,是得要去深入研究研究的.通过这个过程我觉得,从应用层面来讲,想实现一个功能很简单,但若想

10款实用Android UI工具库

移动应用的UI设计就好似达摩克利斯之剑,一方面,一个视觉.交互.体验良好的UI可以加强应用在用户心目中的形象和识别性.而另一方面,一个体验糟糕的UI设计不仅无法让用户沉浸在应用中,还会造成用户对应用产生厌恶感.所以说在进行应用开发时,一个高质量的UI对于提高应用下载量有着非常重要的作用.对此,本文特为广大的移动应用开发者献上10款非常实用的Android UI设计工具. ActionBarSherlock:一个独立的设计库,也是GitHub上很火的一个开源项目 Nine Old Androids

Android UI相关开源项目库汇总

最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽屉菜单 MaterialDrawer ★7337 - 安卓抽屉效果实现方案 Side-Menu.Android ★3865 - 创意边侧菜单 FlowingDrawer ★1744 - 向右滑动流动抽屉效果 SlidingRootNav ★1338 - 仿DrawerLayout的View

Android UI组件之EditText 实现网站注册效果的校验

时间过得太快,还没有什么感觉就到周末了,人生五十载,如梦亦如幻.不过我还没那么老.前两天曾说过,如果需要实现输入IP的功能,那么我们可以整一个自定义控件,然后对他进行事件监听,巴拉巴拉一大堆,好不容易做完了.后来想想,这是为了符合我们平常在PC上的习惯而去自定义的.那么如果只是单纯的为了输入一个IP地址,然后得到结果,不想去这么折腾,有没有什么好办法呢? 很显然是有的,那就今天就来看看Android最常用的组件之一的EditText,虽然之前用的也是EditText,但是侧重点其实是自定义控件,

Android UI设计规则

Android UI技巧 1.1 不该做什么 l  不要照搬你在其它平台的UI设计,应该让用户使用感觉是在真正使用一个Android软件,在你的LOGO显示和平台整体观感之间做好平衡 l  不要过度使用模态对话框 l  不要使用px单位,使用dp或者为文本使用sp l  不要使用固定的绝对定位的布局 l  不要使用太小的字体 1.2 该做什么 l  要为高分辨率的屏幕创建资源 l  要使用适当的间距 l  要正确管理活动(Activity) l  要正确处理屏幕的方向变化 l  需要点击的元素要

Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)

Android UI学习 - ListView 2010-06-20 18:21:35 标签:Android UI 移动开发 ListView ListActivity 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://android.blog.51cto.com/268543/336162 ListActivity ListActivity是一个专门显示ListView的Activity类,它内置了ListView对象,只要我