在Android中单击外部时隐藏加载微调器

Ram*_*ran 7 android spinner

我正在使用带有一组项目的加载微调器动画.如果你点击它外面,它应该消失.有人知道怎么做这个吗?

微调

我试过这个.它正在使用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;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Ily*_*okh 0

链接有解决办法Dialog

那么,为什么不尝试创建一个看起来像旋转器的自定义对话框(简单的示例)呢?使用单选按钮为对话框创建布局文件。

当用户单击单选按钮时,dialog.dismiss()接下来调用并执行必要的代码