0

As a part of my application, I want the android default keypad to be displayed on starting of the application, I got the following code from the forum, but it is not working.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    InputMethodManager imm;
    imm = = (InputMethodManager) gettSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, inputMethodManager.HIDE_IMPLICIT_ONLY);

Please let me know, if I am doing anything wrong, or is there any other way to accomplish the functionality.

Thanks in advance

kaderud
  • 5,457
  • 2
  • 36
  • 49
user977816
  • 81
  • 1
  • 3

3 Answers3

0

I'm doing something similar. But it requires an EditText in the layout.

private EditText editText;

void showKeyboard() {
    this.editText.requestFocus();
    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(this.editText, InputMethodManager.SHOW_IMPLICIT);
}
ottel142
  • 2,016
  • 1
  • 26
  • 37
0

If you have an EditText in the layout, use this:

EditText editText = (EditText) findViewById(R.id.editText);
editText.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

Alternatively, if you don't have an EditText in the layout and still need to show the Soft Keyboard, use this:

this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Note: for the second alternative, the import necessary for the LayoutParams is:import android.view.WindowManager.LayoutParams;

Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
0

You just need to Change in your manifest.xml file

<activity android:name=".MyActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" />

Check out this for Details.

By Doing this Device's Keyboard will be open when load Application.

Community
  • 1
  • 1
Miral Dhokiya
  • 1,720
  • 13
  • 26