I'm a noob to android development and I am trying to figure out how to display the NewQuickAction3D popup dialog at a specific coordinate in a view. I am integrating the popup with this tutorial. Essentially, I want to use the popup dialog to display data where the users touch instead painting on the canvas using "infoview" Currently, the popup displays at the top¢er of the view that I anchor it to. How can i make it display a particular coordinate? Any help is greatly appreciated.
MY CODE
public void updateMsg(String t_info, float t_x, float t_y, int t_c){
infoView.updateInfo(t_info, t_x, t_y, t_c); //Infoview paints to on a specific coordinate
quickAction.show(infoView); //How do I use the t_x & t_y coordinates here instead of just anchoring infoview
EDIT
public void updateMsg(String t_info, float t_x, float t_y, int t_c){
infoView.updateInfo(t_info, t_x, t_y, t_c);
WindowManager.LayoutParams wmlp = quickAction.getWindow().getAttributes(); //Error here getting window attributes
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
quickAction.show(infoView);
}
The dialog position can be set using the position property by providing custom X and Y coordinates. The dialog can be positioned inside the target based on the given X and Y values.
You can Use Align widget and align your dialog widget as per your need. Here in example i am setting it to the bottomCenter that is Alignment(0, 1) . Example code: Align( alignment: Alignment(0, 1), child: Material( shape: RoundedRectangleBorder(borderRadius: BorderRadius.
This example demonstrate about how to make custom dialog in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With