how to get Activity's windowToken without view?

后端 未结 7 1136
南方客
南方客 2021-02-01 14:38

Now, I try to hide the softkeyboard when user touch outside the keyboard:

((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(         


        
7条回答
  •  天涯浪人
    2021-02-01 15:05

    In kotlin:

    val imm  = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.hideSoftInputFromWindow(window.attributes.token, 0)
    

    Or, If you have a view:

    imm.hideSoftInputFromWindow(view.windowToken, 0)
    

提交回复
热议问题