Android SearchView onclick

前端 未结 5 1838
迷失自我
迷失自我 2021-02-19 09:03

I have a searchView which looks like this:

private void setupSearchView() {
    mSearchView = (SearchView) getActivity().findViewById(
            R.id.search_vi         


        
5条回答
  •  猫巷女王i
    2021-02-19 09:42

    A search widget that intercepts all touches on its children and does a callback on touch down:

    class InterceptTouchSearchView(context: Context, attrs: AttributeSet) : SearchView(context, attrs) {
    
      var onActionDownIntercepted: (() -> (Unit))? = null
    
      override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return true
      }
    
      @SuppressLint("ClickableViewAccessibility")
      override fun onTouchEvent(ev: MotionEvent?): Boolean {
        if (ev?.action == MotionEvent.ACTION_DOWN) {
          onActionDownIntercepted?.invoke()
        }
        return false
      }
    }
    

    Usage: search_view.onActionDownIntercepted = { onSearchFieldClicked() }

提交回复
热议问题