1

I am developing chat application. WhenI click Take picture button my keyboard appears and the new intent starts. When I take the picture and return to chat application, the keyboard is hidden. I want the keyboard to remain appeared.

Anyone else had this problem?

Thanks!

ישו אוהב אותך
  • 22,515
  • 9
  • 59
  • 80
File
  • 171
  • 1
  • 2
  • 11
  • That might be happening because focus is getting lost. Can you post your code? – Badrul Jul 15 '14 at 11:03
  • Possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Anand Savjani Oct 28 '16 at 04:28

4 Answers4

1

To show soft keyboard do this:

//Import this
import android.view.inputmethod.InputMethodManager;

//Create object
private InputMethodManager imm;

imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
Badrul
  • 1,462
  • 4
  • 15
  • 26
1

In my case, I need to open the keyboard within onActivityResult() after getting a picture from Gallery or taking a picture via camera.

To make it works, I have to put a delay like 500 ms. Otherwise, it will not open the keyboard.

Here is my code inside onActivityResult():

// Set original file name to description.
EditText etDescription = getView().findViewById(R.id.etAttachmentDescription);
etDescription.setText(fileName);
etDescription.selectAll();
etDescription.requestFocus();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        // Open keyboard after 500ms
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
}, 500);
Yusril Maulidan Raji
  • 1,380
  • 1
  • 17
  • 39
0

please use this method to hide your soft keyboard .call this method from onactivity result.

public static void hideSoftKeyboard(Activity context) {
        InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputManager != null)
        inputManager.hideSoftInputFromWindow(context.getWindow().getDecorView().getApplicationWindowToken(), 0);
        context.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    }
bhavesh kaila
  • 756
  • 5
  • 25
0

@Badrul's solution worked for me but I had to requestFocus() on the edit text view first, but it worked great.

mEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
ישו אוהב אותך
  • 22,515
  • 9
  • 59
  • 80
the.joeba
  • 196
  • 2
  • 6