9

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.

andrewgda
  • 153
  • 1
  • 10

4 Answers4

1

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);
Phakin
  • 125
  • 2
  • 13
0

This answer is based on the following assumption: You are using a WebView in your android app to insert a custom Javascript to achieve a certain task

Firstly create a method in your Android java class that will do do the job of popping up the keyboard:

@JavascriptInterface
public void takeUserInput() {
     mWebView.setFocusable(true);
     mWebView.setFocusableInTouchMode(true);
}

In your Javascript make a call to the takeUserInput() method whenever you want to pop-up the keyboard.

You can read up on how to call android functions from Javascript.

Hope this helps!

Kriti Sharan
  • 281
  • 1
  • 3
  • 10
0

You have to make sure that the window's soft input mode is set to "always visible" before requesting focus on your element. You can set it using:

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

After that you can bring up the keyboard by requesting focus on your element:

element.requestFocus();
0

According to my Knowledge you can't open the keyboard without using a input. Try to use virtual keyboard read following.

Show virtual keyboard on mobile phones in javascript

Nisal Edu
  • 7,237
  • 4
  • 28
  • 34