Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Activity activity = getActivity();
  2. InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
  3. try
  4. {
  5. inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
  6. }
  7. catch (Exception e)
  8. {
  9.  
  10. }
  11.  
  12. InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
  13. imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
  14.  
  15. class MyFrag extends Fragment{
  16.  
  17. @Override
  18. public void onConfigurationChanged(Configuration config){
  19. //Check flags
  20. switch(config.keyboardHidden){
  21. case KEYBOARDHIDDEN_NO:
  22. // do something
  23. break;
  24. case KEYBOARDHIDDEN_YES:
  25. break;
  26. }
  27. }
  28.  
  29. }
  30.  
  31. <activity ...
  32. android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"/>
  33.  
  34. Configuration config = getResources().getConfiguration();
  35.  
  36. @Override
  37. protected void onPause() {
  38. super.onPause();
  39.  
  40. final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
  41. if (inputMethodManager != null && inputMethodManager.isActive()) {
  42. if (getCurrentFocus() != null) {
  43. inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement