Android KitKat上的对话似乎被削减了

Hac*_*eto 21 android dialog android-4.4-kitkat

我使用了一个Activity的对话框主题,它在Android <= 4.3上工作正常但在最新的KitKat 4.4上没有.这是问题的截图:

对话框android 4.4问题

缺少布局的顶部.你可以看到界限似乎被削减了.

我正在使用Android模拟器来测试应用程序,因此我不知道问题是由于虚拟机还是由于某些其他原因.

小智 36

您可以从下面的代码中解决问题.

dialog.getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)


小智 9

您应该扩展Dialog并在onCreate调用中使用以下方法:

@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);
}
Run Code Online (Sandbox Code Playgroud)