Search code examples
androidandroid-softkeyboardactivitygroupandroid-tabactivity

How to hide only soft keyboard android


In my application i am using tab activity and activity group. In one of the activity i have edit texts. When the user click on the edit text, soft keyboard appears. But when the user click on the back button the soft key board dismisses and the previous activity on the activity stack appears.

Earlier on other application when i press back button when there is soft keyboard on the screen, only soft keyboard dismiss and it wouldn't go back to previous activity unless i press the back button again. I want this to happen in my current application as well. Plz Help.


Solution

  •  InputMethodManager imm = (InputMethodManager) 
                  this.getSystemService(Context.INPUT_METHOD_SERVICE);
    
            if (imm.isAcceptingText()) {
    
                System.out.println("Software Keyboard was shown");
    
            } else {
    
                 System.out.println("Software Keyboard is hidden");
    
                 }  
    

    This does the trick. I checked if the soft key board is opened it stays at the current activity, otherwise it goes to previous activity.