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