Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open keyboard on Android by javascript without click or touch event?

Is it possible to open keyboard on Android without click or touch event? For example just after appending textarea to some element? element.focus() works for me on iOS but not on Android.

like image 986
andrewgda Avatar asked Jan 08 '15 08:01

andrewgda


1 Answers

Simply add "requestFocus" to your XML. Something like

        <EditText
        android:id="@+id/editText"
        ... />
        <requestFocus />

and in onCreate()

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Or: It could be just

editText.requestFocus();
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
like image 87
Phakin Avatar answered Oct 24 '22 21:10

Phakin