Question

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.

Was it helpful?

Solution 3

 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.

OTHER TIPS

Use below in your On create Method. it is working fine.

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

can try this- **

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                                  imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

**

code

InputMethodManager imm = (InputMethodManager)getSystemService(
  Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

check below link also :-

http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

I think this will help you

protected void hideSoftKeyboard(EditText input) {
        input.setInputType(0);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(input.getWindowToken(), 0);

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top