我正在使用加载微调器动画和一组项目。如果你点击它外面,它应该消失。有人知道怎么做这个吗?在Android中单击它之外时隐藏加载微调器
我已经试过这一点。它与EditText
一起工作。但它不工作的提前Spinner
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
View view = getCurrentFocus();
boolean ret = super.dispatchTouchEvent(event);
if (view instanceof EditText||view instanceof Spinner) {
View w = getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = event.getRawX() + w.getLeft() - scrcoords[0];
float y = event.getRawY() + w.getTop() - scrcoords[1];
if (event.getAction() == MotionEvent.ACTION_UP
&& (x < w.getLeft() || x >= w.getRight()
|| y < w.getTop() || y > w.getBottom())) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
return ret;
}
感谢。
看看http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog/8384124#8384124 – user370305
我已经检查过这个链接。但是可以进行对话而不是微调。 –
你必须检查你的活动窗口(Spinner之外)的触摸。我在那个答案中提到了。 – user370305