How to delete or change the searchview icon inside the SearchView actionBar?

后端 未结 8 2241
臣服心动
臣服心动 2020-12-17 04:57

\"screenshot\"

How to remove or change the search view icon inside the edittext? I am using the Appcompat libra

8条回答
  •  余生分开走
    2020-12-17 05:27

    remove is the right drawable that you have mentioned in xml:

    final Drawable remove = ContextCompat.getDrawable(getActivity(), R.drawable.ic_close_circle);
            etSearchProducts.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent event) {
                    if (etSearchProducts.getCompoundDrawables()[2] == null) {
                        return false;
                    }
                    if (event.getAction() != MotionEvent.ACTION_UP) {
                        return false;
                    }
                    if (event.getX() > etSearchProducts.getWidth() - etSearchProducts.getPaddingRight() - remove.getIntrinsicWidth()) {
                        etSearchProducts.setText("");
                        Utility.hideKeyboard(getActivity());
                    }
    
                    return false;
                }
            });
    

提交回复
热议问题