Lollipop导航栏重叠Dialog with Gravity.Bottom

时间:2018-02-28 01:30:37

标签: android dialog android-4.4-kitkat android-immersive android-navigation-bar

我遵循here概述的技术,让我的Dialog浮动到屏幕底部并占据整个宽度,类似于抽屉。除了Lollipop之外,这适用于我定位的每个Android版本(16+)。对话框将浮动在软件导航按钮(背面,主页和堆栈)后面,因此无法按下对话框上的消极或正面按钮。

我已尝试过概述here的方法,但未成功。我考虑在我的所有对话框中添加底部填充 - 但这意味着我必须设置自定义视图,而不是使用alertdialog构建器其他方法。我认为可能有办法避免这种情况,我找不到。

编辑1:

我现在通过禁用全屏,沉浸式和隐藏导航的标记来尝试setSystemUiVisibility方法。但是,对话框在创建时仍然位于屏幕上的导航按钮后面(在API 22中测试)。我也试过了

decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

这是我目前的代码:

@Override
public void onStart()
{
    super.onStart();

    AlertDialog dlg = (AlertDialog) getDialog();

    Window window = dlg.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.BOTTOM;

    window.setAttributes(params);
    View decor = window.getDecorView();
    int flagset = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    decor.setSystemUiVisibility(decor.getSystemUiVisibility() & ~flagset);

}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Theme_DialogTheme);
    //various methods adding elements to dialog

    Dialog dlg = builder.create();

    return dlg;

}

和我的风格:

<style name="Theme.SnapTrash" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:statusBarColor">@android:color/black</item>
    <item name="colorPrimary">@color/colorSnapTrashPrimary</item>
    <item name="android:colorBackground">@color/colorSnapTrashPrimary</item>
    <item name="android:textColorPrimary">@color/colorSnapTrashTextPrimary</item>
    <item name="android:windowBackground">?android:attr/colorBackground</item>
    <item name="colorAccent">@color/colorSnapTrashAccent</item>
    <item name="colorPrimaryDark">@color/colorSnapTrashPrimaryDark</item>
    <item name="android:colorForeground">@android:color/black</item>
    <item name="android:textColorPrimaryInverse">@color/colorSnapTrashTextPrimaryInverse</item>
    <item name="android:navigationBarColor">@android:color/black</item>
    <item name="android:textColorSecondaryInverse">@color/secondary_text_material_dark</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    <item name="android:windowTranslucentNavigation">false</item>

</style>

<style name="Theme.DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:textColor">#FFEF5350</item>
    <item name="android:textColorPrimary">#FFEF5350</item>
    <item name="android:colorAccent">#999</item>
</style>

1 个答案:

答案 0 :(得分:0)

您的导航栏是否半透明?你的对话框在导航栏后面吗?如果是这样,你可以设置对话框的主题。例如,你可以设置对话框的窗口标志不是全屏,而不是半透明。如果它不起作用,你可以设置UI标志这种方法:setSystemUiVisibility(int arg)