更改android对话框垂直位置(在运行时)不起作用

时间:2015-11-11 20:01:34

标签: android android-layout android-activity android-alertdialog android-dialog

我需要在运行时发生某些事情时将对话框移到上面,所以我正在尝试以下代码但不起作用:

    final Dialog dialog = new Dialog(CategoryActivity.this, R.style.DishDetailDialogStyle);
    dialog.setContentView(R.layout.category_dish_dialog);
    ColorDrawable semiTransparentBg = new ColorDrawable(Color.parseColor("#90000000")); //#ALPHA, RED, GREEN & BLUE
    dialog.getWindow().setBackgroundDrawable(semiTransparentBg);

    WindowManager.LayoutParams params = dialog.getWindow().getAttributes();

    params.gravity = Gravity.TOP;
    params.y = 900;

    dialog.getWindow().setAttributes(params);

    dialog.show();

这是应用于对话框的样式(DishDetailDialogStyle):

<style name="DishDetailDialogStyle">
    <item name="android:windowFullscreen">false</item>
</style>

0 个答案:

没有答案