更改对话框在屏幕上的位置android [英] Changing position of the Dialog on screen android

查看:212
本文介绍了更改对话框在屏幕上的位置android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在活动中做了一个简单的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆