Dialog on Android KitKat seems to be cut

后端 未结 6 2057
鱼传尺愫
鱼传尺愫 2020-12-08 15:35

I used dialog theme for an Activity and it works fine on Android <= 4.3 but not on the latest KitKat 4.4. Here\'s a screenshot of the problem:

6条回答
  •  难免孤独
    2020-12-08 15:57

    You should extend the Dialog and in the onCreate call the following method:

    @TargetApi(14)
    public void toggleHideBar() {
    
        if (Build.VERSION.SDK_INT < 18) {
            return;
        }
    
        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        boolean isImmersiveModeEnabled =
                ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
        if (isImmersiveModeEnabled) {
            Log.d("dialog", "Turning immersive mode mode off.");
        } else {
            Log.d("dialog", "Turning immersive mode mode on.");
        }
    
        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16 && (newUiOptions & View.SYSTEM_UI_FLAG_FULLSCREEN) <= 0) {
            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) <= 0) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
    
        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    }
    

提交回复
热议问题