美文网首页
EditText的搜索输入,弹出PopupWindow

EditText的搜索输入,弹出PopupWindow

作者: sunny635533 | 来源:发表于2022-03-14 18:17 被阅读0次

在EditText添加TextWatcher的事件,afterTextChanged方法里添加数据接口的调用,然后弹出popupWindow,具体如下:

 public void showCarNumberWindow(View anchor) {
        if (carListPopup == null) {
            carListPopup = new PopupWindow(this);
            carListPopup.setWidth(anchor.getWidth()+20);
            carListPopup.setHeight(ScreenUtils.dp2px(this, 220));
            carListPopup.setBackgroundDrawable(new ColorDrawable(0x00000000));
            carListPopup.setOutsideTouchable(true);
            carListPopup.setFocusable(false);

            View view = LayoutInflater.from(this).inflate(R.layout.car_numer_list, null);
            carListPopup.setContentView(view);
        } else {
            carItemAdatper.setNewData(mReceiveGoodsViewModel.mCarList.getValue());
        }

        if (!carListPopup.isShowing()) {
            carListPopup.showAsDropDown(anchor);
        }
    }

setFocusable(false),必须要设置为false,不然会影响组件的键盘输入和android的返回键。

相关文章

网友评论

      本文标题:EditText的搜索输入,弹出PopupWindow

      本文链接:https://www.haomeiwen.com/subject/agqsdrtx.html