在屏幕的任何位置显示AlertDialog [英] Show AlertDialog in any position of the screen

查看:621
本文介绍了在屏幕的任何位置显示AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们表现出AlertDialog Android中它显示在屏幕中央。有没有什么办法可以改变位置?

When we show an AlertDialog in android it shows in the center of the screen. Is there any way to change the position?

推荐答案

寻找各种职位后,我已经找到了解决方案。

After searching in various post I have found the solution.

在code张贴如下:

private CharSequence[] items = {"Set as Ringtone", "Set as Alarm"};
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {

            if(item == 0) {

            } else if(item == 1) {

            } else if(item == 2) {

            }
        }
    });

     AlertDialog dialog = builder.create();
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
     WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();

 wmlp.gravity = Gravity.TOP | Gravity.LEFT;
 wmlp.x = 100;   //x position
 wmlp.y = 100;   //y position

 dialog.show();

下面x位置的值是像素从左至右。对于y位置值是从底部到顶部。

Here x position's value is pixels from left to right. For y position value is from bottom to top.

这篇关于在屏幕的任何位置显示AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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