android: softkeyboard not shown after return to ac

2019-09-20 19:43发布

问题:

My activity is panned in order to make space for soft keyboard(keyboard is visible).

When I leave activity in this state by pressing home button, after return to this activity, layout remains panned, but keyboard is not shown. I'd love keyboard to be shown in this situation, or layout to slide down. Can somebody please help me, how to do that?

I don't want to use android:windowSoftInputMode="stateVisible" because I don't want keyboard to be shown by default.

回答1:

So there must be some problem with fullscreen activities. When I change my activity from fullscreen to for example NoTitleBar, everything works fine.

When using fullscreen activities, the goal is to force redraw/remeasure screen in onRestart method. For this issue with fullscreen activities, I found workaround here



回答2:

You can try this piece of code when you want to show the keyboard :

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);