1.首先UI Visibility Flag分为:
/*View has requested the system UI (status bar) to be visible (the default).*/
1.View.SYSTEM_UI_FLAG_VISIBLE;
/*View has requested the system UI to enter an unobtrusive "low profile" mode.*/
2.View.SYSTEM_UI_FLAG_LOW_PROFILE;
/*View has requested to go into the normal fullscreen mode so that its content can take
*over the screen while still allowing the user to interact with the application.
*/
3.View.SYSTEM_UI_FLAG_FULLSCREEN;
/*View has requested that the system navigation be temporarily hidden.*/
4.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
/* Flag for {@link #setSystemUiVisibility(int)}: When using other layout
* flags, we would like a stable view of the content insets given to
* {@link #fitSystemWindows(Rect)}. This means that the insets seen there
* will always represent the worst case that the application can expect
* as a continuous state. In the stock Android UI this is the space for
* the system bar, nav bar, and status bar, but not more transient elements
* such as an input method.
*/
5.View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
/* Flag for {@link #setSystemUiVisibility(int)}: View would like its window to be laid out as if it has requested */
6.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
/**
* Flag for {@link #setSystemUiVisibility(int)}: View would like its window
* to be laid out as if it has requested
* {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This
* allows it to avoid artifacts when switching in and out of that mode, at
* the expense that some of its user interface may be covered by screen
* decorations when they are shown. You can perform layout of your inner
* UI elements to account for non-fullscreen system UI through the
* {@link #fitSystemWindows(Rect)} method.*/
7.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
/**
* Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
* hiding the navigation bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. If this flag is
* not set, {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any
* user interaction.
* <p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only has an effect when used in combination with that flag.</p>
*/
8.View.SYSTEM_UI_FLAG_IMMERSIVE;
/**
* Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
* hiding the status bar with {@link #SYSTEM_UI_FLAG_FULLSCREEN} and/or hiding the navigation
* bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. Use this flag to create an immersive
* experience while also hiding the system bars. If this flag is not set,
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any user
* interaction, and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be force-cleared by the system
* if the user swipes from the top of the screen.
* <p>When system bars are hidden in immersive mode, they can be revealed temporarily with
* system gestures, such as swiping from the top of the screen. These transient system bars
* will overlay app’s content, may have some degree of transparency, and will automatically
* hide after a short timeout.
* </p><p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_FULLSCREEN} and
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only has an effect when used in combination
* with one or both of those flags.</p>
*/
9.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
/** Flag for {@link #setSystemUiVisibility(int)}: Requests the status bar to draw in a mode that is compatible with light status bar backgrounds.*/
10.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
2.分类看效果
View decorView = getWindow().getDecorView();
//statusbar 部分图标会直接变为灰点,但是在国内手机无效,google亲儿子上有效
//decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
//statusbar消失,页面布局占据statusbar区域,但是下拉显示通知的时候,statusbar会出现,也就是这个flag会失效,同时由于statusbar的出现,会导致界面跳动
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
//navigationbar会消失,同时,页面布局会占据navigationbar的位置,同时,在与界面产生交互(比如touch下界面,即使没有设置touch回调),flag会失效,同时navigationbar就会显示,界面同样会跳动
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//statusbar+navigationbar消失,同时页面布局占据二者位置,同时,在与界面产生交互(比如touch下界面,即使没有设置touch回调),flag会失效,同时navigationbar+statusbar会显示,界面同样会跳动
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//单独使用无任何效果,需要配合fullscreen||hide_navigation等使用
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//单独使用,没看到效果(target:16)
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
//statusbar+navigationbar均没有变化,但是,应用的布局会上顶,部分会被statusbar覆盖
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
//单独使用没看到效果(target:19)
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE);
//单独使用没看到效果(target:19)
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
//statusbar的字体颜色会由白色(默认)变为黑色
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
3.沉浸式状态栏/透明状态栏
简而言之就是:
1.沉浸式:应用中不应该看到状态栏/导航栏,这种效果在应用中比较少见,一般用在游戏中
2.透明:状态栏透明,颜色字体由具体应用指定
网友评论