Reference:
Hide the Navigationhttps://developer.android.com/training/system-ui/navigation.html
Responding to UI Visibility Changes
https://developer.android.com/training/system-ui/visibility.html
Using Immersive Full-Screen Mode
https://developer.android.com/training/system-ui/immersive.html
Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.
|
SYSTEM_UI_FLAG_VISIBLE = 0
SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002
SYSTEM_UI_FLAG_IMMERSIVE = 0x00000800
SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 0x00001000
Code snippet:
Hide the Navigation:public void showNavigationBar(boolean showNavigationBar) {
int flags = View.SYSTEM_UI_FLAG_VISIBLE;
if (!showNavigationBar) {
flags |= (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
getWindow().getDecorView().setSystemUiVisibility(flags);
}
Responding to UI Visibility Changes:
private View mDecorView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_disable_home_key_demo);
mDecorView = getWindow().getDecorView();
mDecorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
}
沒有留言:
張貼留言