Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get Activity's windowToken without view?

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

((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(editView.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);

I want put the logic in my base activity class, so if it is possible to getWindowToken without View?

like image 249
David Guo Avatar asked Oct 17 '11 04:10

David Guo


3 Answers

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()
like image 62
divonas Avatar answered Nov 04 '22 01:11

divonas


Surely you can use:

getContentView().getWindowToken()

or you can refer to SO Quest

like image 19
Hanry Avatar answered Nov 04 '22 01:11

Hanry


Simply use getWindow().getDecorView().getWindowToken()

like image 7
Bertram Gilfoyle Avatar answered Nov 04 '22 01:11

Bertram Gilfoyle