How Do I Position Custom Dialog at specific Coordinate?

一笑奈何 提交于 2019-12-05 09:45:58
Raghunandan

Override onTouch() of your view

AlertDialog dialog;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

            showDialog();  // display dialog
            break;
        case MotionEvent.ACTION_MOVE:
            if(dialog!=null)
              dialog.dismiss(); 
             // do something
            break;
        case MotionEvent.ACTION_UP:
            // do somethig
            break;
    }
    return true;
    } 
     public void showDialog()
      {

             AlertDialog.Builder builder = new AlertDialog.Builder(FingerPaintActivity.this);
             dialog = builder.create();
             dialog.setTitle("my dialog");
             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();
      }

Even to draw user touches the screen then also dialog is displayed. so dismiss dialog in on move.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!