像这样:
http://ecee.colorado.edu/ecen3000/labs/lab8/files/javaLab1_files/image020.jpg
全部谢谢...................
我试过
public void showMenu(View v) {
PopupMenu popup = new PopupMenu(this, v);
// This activity implements OnMenuItemClickListener
popup.setOnMenuItemClickListener((OnMenuItemClickListener) this);
popup.inflate(R.menu.actions);
popup.show();
}
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
default:
return false;
}
}
答案 0 :(得分:0)
触摸屏幕左侧需要弹出。我的建议是首先必须为在xml中创建的根布局添加setOnTouchListener。
并且通过使用下面的覆盖方法,你可以获得x和y位置的触摸事件 手指放在屏幕上,然后根据需要将范围限制为角落,并比较触摸x和y,如果它在范围之间,则弹出你的diaglog。
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
//finger placed down, this will run
}
else if (action == MotionEvent.ACTION_UP) {
//finger is up, this will run
}
else if (action == MotionEvent.ACTION_MOVE) {
//finger is moved, this will run
为了清楚了解,请查看此链接(http://www.vogella.com/tutorials/AndroidTouch/article.html)