Can anybody tell 开发者_开发问答how to place dialog or popup window at clicked place in Android?
I think you need a QuickAction Dialog
How to Create QuickAction Dialog in Android
Notes: Create One popuplayout.xml file and parent LinearLayout name give popup_menu_root and three button name is popup_menu_button1,popup_menu_button2,popup_menu_button3 create main.xml file and put one button Create MainActivity.java setContentView(R.layout.main.xml); then button click event this code write
OR
And This Code Write in Your Click Event Then Point Position Set X And Y to last Line Of Code. // get the instance of the LayoutInflater LayoutInflater inflater = (LayoutInflater) Popup.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // inflate our view from the corresponding XML file View layout = inflater.inflate(R.layout.popuplayout,(ViewGroup) findViewById(R.id.popup_menu_root)); // create a 100px width and 200px height popup window final PopupWindow pw = new PopupWindow(layout, 200, 200, false); pw.showAtLocation(layout, Gravity.NO_GRAVITY, 100, 250); // set actions to buttons we have in our popup Button button1 = (Button) layout .findViewById(R.id.popup_menu_button1); button1.setOnClickListener(new OnClickListener() { public void onClick(View vv) { // close the popup pw.dismiss(); } }); Button button2 = (Button) layout .findViewById(R.id.popup_menu_button2); button2.setOnClickListener(new OnClickListener() { public void onClick(View vv) { Toast.makeText(Popup.this, "Hello", Toast.LENGTH_LONG) .show(); } }); Button button3 = (Button) layout .findViewById(R.id.popup_menu_button3); button3.setOnClickListener(new OnClickListener() { public void onClick(View vv) { finish(); } }); // finally show the popup in the center of the window or any position // pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
精彩评论