-1

I want to open the soft keyboard in android automatically after opening the activity . I used the code mentioned here Close/hide the Android Soft Keyboard but it doesn't work. This is my code.

final EditText txtName = (EditText) findViewById(R.id.etxt_hidenprac);
txtName.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        txtName.post(new Runnable() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) Practice.this.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(txtName, InputMethodManager.SHOW_IMPLICIT);
            }
        });
    }
});
txtName.requestFocus();




<activity
    android:name="com.example.moisun01.Practice"
    android:label="@string/app_name"
    android:screenOrientation="landscape" 
    android:windowSoftInputMode="stateVisible">
</activity>

I found it why it doesn't work . its because my layout is in landscape orientation. and in portrate orientation it works fine. but my App is in landscape . is there any solution for this problem?

Community
  • 1
  • 1
sun1987
  • 211
  • 1
  • 2
  • 14

4 Answers4

0

In the Activiy onCreate() you can write like this. InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEditText, 0);

or ,in the Manifest file you can use android:windowSoftInputMode="stateVisible" under activity.

m.v.n.kalyani
  • 730
  • 7
  • 20
  • InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY); imm.showSoftInput(etxt_practice,InputMethodManager.SHOW_FORCED); – sun1987 Apr 11 '15 at 18:02
0

(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEditText, 0);

or ,in the Manifest file you can use android:windowSoftInputMode="stateVisible" under activity.

m.v.n.kalyani
  • 730
  • 7
  • 20
0

answer is already given in comment box... it worked for me.. You dont need to do too much...just Add

android:windowSoftInputMode="stateVisible"

in your activity tag in manifest file In this way soft keyboard in android automatically opens as activity start

..if this wasn't happening to you.. then..try to give focus to first edittext usin requestFocus() method

Angad Tiwari
  • 1,653
  • 1
  • 10
  • 22
0

Maybe try this:

onCreate method

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