full screen application android

后端 未结 8 753
暖寄归人
暖寄归人 2020-12-06 02:08

i have two questions:

  1. one how can i run my application in full screen
  2. how video players run videos in full screen.

i have tried alot an

相关标签:
8条回答
  • 2020-12-06 02:32

    On the new android 4.4 you should add this line:

    View.SYSTEM_UI_FLAG_IMMERSIVE;
    

    So the new working solution atleast on nexus4 4.4.2 is

    final int mUIFlag = 
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LOW_PROFILE
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_IMMERSIVE;
    

    Immersive alone won't work though it works when combined with other flags. see documentation for more details. Then you add in the activity the activating of this setup as shown here before (I am just adding for consistency)

    getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
    
    0 讨论(0)
  • 2020-12-06 02:37

    I'm not sure what you're after, but the following hides the Notification bar, and the Soft Navigation keys (as seen on Google Nexus-devices), so the app essentially is "full screen".

    Edit2

    In Android 4.4 (API 19) Google introduced the new Immersive mode which can hide the status & navbar and allow for a truly fullscreen UI.

    // This snippet hides the system bars.
    private void hideSystemUI() {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        mDecorView.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 // hide nav bar
                  | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                  | View.SYSTEM_UI_FLAG_IMMERSIVE);
    }
    
    // This snippet shows the system bars. It does this by removing all the flags
    // except for the ones that make the content appear under the system bars.
    private void showSystemUI() {
        mDecorView.setSystemUiVisibility(
                   View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    

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

    Edit:
    Tested on Android 4.3 (API 18) and Android 4.1 (API 16) with Soft Nav keys.

    @Override
    protected void onCreate(Bundle b) {
        super.onCreate(b);
    
        setContentView(R.layout.main);
    
        int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    
        getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
    }
    

    For more information read up on http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)

    0 讨论(0)
提交回复
热议问题