1

I have an EditText in my activity class. What I want is, whenever my activity starts it automatically opens the input keyboard along with EditText. So how that can be done? Please anyone suggest it to me, if possible with example

chemdork123
  • 12,369
  • 2
  • 16
  • 32
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • is your activity is launcher? – Niranj Patel Sep 21 '11 at 10:46
  • Wouldn't `focus()`ing the text box cause the SIP to be displayed automatically? Leaving things to the OS can be good for consistency. – Vladislav Zorov Sep 21 '11 at 11:38
  • if your activity is launcher then please see [this question](http://stackoverflow.com/questions/7200281/programatically-hide-show-android-soft-keyboard/7200308#7200308) and also read all comment of my answer .. – Niranj Patel Sep 21 '11 at 10:53

4 Answers4

2

If you want to always show soft keyboard whenever your activity is started, the simplest way is to add this piece of code in your Android Manifest file:

<activity android:name=".YourActivity"
          android:windowSoftInputMode="stateAlwaysVisible" />

This will just work without you doing anything else with your code.

  • yeh its working..but the thing is that in my inputKeyboard "done" button is missing even i give inputtype="textPassword" – AndroidDev Sep 21 '11 at 10:51
1

add this in your manifest file this will do

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
0

here is another method:-

EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
0

set this flag in activity's onCreate() method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Vijay
  • 2,005
  • 1
  • 14
  • 15