How to hide the soft-key bar on Android phone?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 07:11:26

问题


 

When my app starts, I'd like to hide the soft keys bar (in red rectangle) to have a larger screen.

  1. How can I hide it?

  2. Do I need to show the bar purposely when the app quits? Or it will restore itself automatically after the app quits?

Android 4.1, with no hardware keys on phone front.


回答1:


Try

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

From official doc

The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.

The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.

The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required.

The behavior of the nav bar is app dependent IIRC, so it should show again after the user leaves your app.




回答2:


I know its late but it is the right answer so what you are trying to do is what called immersive mode. for (API 19)

check out: https://developer.android.com/training/system-ui/immersive.html

The code that you were asking for is:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}


来源:https://stackoverflow.com/questions/16291640/how-to-hide-the-soft-key-bar-on-android-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!