我在我的Activity中做了一个简单的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();
使用上面的代码,对话框显示在屏幕的(大约)中心.
With above code, the dialog shows at the (about) the center of the screen.
我想知道,如何自定义对话框位置以使其显示在顶部操作栏下方?(无论如何要改变对话框的重力或其他东西?)以及如何根据我的代码来做到这一点??
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??
我用这段代码在屏幕底部显示对话框:
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);
如果需要,此代码还可以防止 android 使对话框的背景变暗.您应该能够更改重力参数以移动对话框
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
这篇关于在屏幕android上更改对话框的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!