Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: softkeyboard not showing up

I have 2 EditTexts in the MainActivity Layout. If i run the application normally the 1st EditText gets focused but the softkeyboard is not openned.

but when i used this:

public class TestingActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        EditText et1 = (EditText) findViewById(R.id.editText1);
        EditText et2 = (EditText) findViewById(R.id.editText2);

        et2.requestFocus();
        InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mInputMethodManager.showSoftInput(et2, InputMethodManager.SHOW_IMPLICIT);
    }
}

expecting the 2nd EditText will get focus and softkeyboard will be openned.

I only get focus, but the softkeyboard is openned only when i click on the EditText.

Thank You

like image 777
Archie.bpgc Avatar asked Sep 28 '12 13:09

Archie.bpgc


People also ask

How do I enable soft keyboard on Android?

To enable your latest Android keyboard, scroll to the bottom and hit the System entry. Then, click Languages & input. Pick Virtual keyboard on the following page. You will find a list of all the existing keyboards on your smartphone here.

How do I force an Android keyboard to show up?

Simple. Download the Gboard - the Google Keyboard – Apps on Google Play - and then go to the settings section on your Android device >> General Management >> Language and Input >> Default Keyboard (Select Gboard).

Why isn't my keyboard showing up on my Samsung?

Navigate to and open Settings, and then scroll and tap Apps. Tap the sort icon and then tap the switch next to Show system apps, and then tap OK. Search for or scroll to Samsung Keyboard, and then tap it.

How do I unhide keyboard on Android?

Under Settings > click on the “Language and Input” option. This option may be available under “System” in some phones. After you click on the “Language and Input” option, click on “Virtual Keyboard” or in “Current Keyboard”.


2 Answers

Try specifying the android:windowSoftInputMode attribute in your AndroidManifest.xml file for your activity.

For example:

<activity android:name=".TestingActivity" android:windowSoftInputMode="stateVisible|adjustResize" />

You probably don't need any of the code that uses InputMethodManager in your Activity.

like image 171
wsanville Avatar answered Sep 27 '22 19:09

wsanville


I notice that one reason for the keyboard not showing up is selecting an inputtype not supported by the specific Android device. For instance InputType.TYPE_NUMBER_VARIATION_NORMAL will not work on my Asus Transformer (no keyboard shows up), while InputType.TYPE_CLASS_NUMBER will work just fine.

like image 41
Terje Lundin Avatar answered Sep 27 '22 18:09

Terje Lundin