how to get Activity's windowToken without view?

后端 未结 7 1108
南方客
南方客 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 14:59

    I faced exactly the same problem, while writing OnPageChangeListener within an Activity. You can use one of these solutions. Either:

    getWindow().getDecorView().getRootView().getWindowToken()   
    

    or:

    findViewById(android.R.id.content).getWind‌​owToken()
    

提交回复
热议问题