改变屏幕上对话框位置 [英] change dialog position on the screen
问题描述
我做了一个简单的 AlertDialog
在我的活动
I made a simple AlertDialog
in my Activity:
View view = layoutInflater.inflate(R.layout.my_dialog, null);
AlertDialog infoDialog = new AlertDialog.Builder(MyActivity.this)
.setView(view)
.create();
infoDialog.show();
使用上述code,在对话框显示在屏幕的(约)的中心。
With above code, the dialog shows at the (about) the center of the screen.
我想知道,我怎么可以自定义对话框的位置,使之显示在顶部操作栏公正? (反正是有改变对话的重心还是什么?),以及如何根据我的code ??
I am wondering, how can I customize the dialog position to make it showing just under the top Action Bar ? (Is there anyway to change the gravity or something of the dialog?) and how to do it based on my code??
推荐答案
我用这个code,以显示在屏幕底部的对话框:
I used this code to show the dialog at the bottom of the screen:
Dialog dlg = <code to create custom dialog>;
Window window = dlg.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
这code也prevents变暗对话框的背景机器人,如果你需要它。你应该能够改变重力参数来移动对话框约
This code also prevents android from dimming the background of the dialog, if you need it. You should be able to change the gravity parameter to move the dialog about
这篇关于改变屏幕上对话框位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!