gpt4 book ai didi

android - 当您在 Android 中点击它的外部时隐藏加载微调器

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:02 24 4
gpt4 key购买 nike

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

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;
}

提前致谢。

最佳答案

我个人所做的是使用 setSingleChoiceItems() 创建自定义 AlertDialog 来做同样的事情。然后我使用了 setCanceledOnTouchOutside()

关于android - 当您在 Android 中点击它的外部时隐藏加载微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com