0

I am building Android app with Kotlin.

I have Fragment and I make keyboard go down if I touch that Fragment with below code.

  view.setOnTouchListener(object : View.OnTouchListener {
            override fun onTouch(view: View?, event: MotionEvent?): Boolean {
                val imm: InputMethodManager =
                    activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
                imm.hideSoftInputFromWindow(view!!.windowToken, 0)
                return true
            }
        })
        return view

But this Fragment has several LinearLayouts in it.

So If I touch / click fragment outside of these layouts, keyboard goes down well.

However If I touch one of these layouts, keyboard is not going down.

I guess It is because layout is positions above this Fragment's view, so touch event is not recognized in layout.

Then should I write setOnTouchListener in all layouts?

I think It has another way to make it with one function.

Please help me.

Hyejung
  • 902
  • 1
  • 8
  • 22

0 Answers0