在 Android 中显示对话框时,有没有办法告诉应用程序显示弹出窗口?

Is there a way when displaying a dialog in Android to tell the app to show the pop up?

我有一个全屏应用程序,其中包含一些按钮,这些按钮在被点击时需要自定义下拉菜单。我正在考虑显示一个自定义对话框,其中包含选项。有没有办法告诉对话框在哪里显示?

如果您想创建一个 Dialog window 您可以通过执行以下操作来更改显示它的屏幕位置:

//Dialog reference
Dialog dialog;

//Instantiate here your dialog
dialog = ... ;

//Get window layout parameters reference
Window window = dialog.getWindow();
WindowManager.LayoutParams windowLayoutParams = window.getAttributes();

//Set the parameters you want
windowLayoutParams.gravity = Gravity.CENTER; //e.g. dialog's will be centered
window.setAttributes(windowLayoutParams);

您可以改为使用 Gravity.BOTTOM 或 Gravity.TOP 来相应地显示对话框。或者,对于更具体的定位,您可以尝试设置属性 "windowLayoutParams.x" & "windowLayoutParams.y".