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.

4
  • 2
    @Vixed you should edit the question to make it fit better your own issue. As-is it is unclear whether it is for an Android native app in Java (as the current answer assumes), or for an hybrid app in JavaScript, e.g. using Cordova. Commented Oct 27, 2017 at 8:04
  • Please clarify does your app is in java or an hybrid app. Commented Oct 27, 2017 at 11:09
  • Webview javascript (jQuery) @ghybs Commented Oct 27, 2017 at 14:57
  • check this stackoverflow.com/questions/9703271/… Commented Oct 30, 2017 at 4:54

4 Answers 4

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);
Sign up to request clarification or add additional context in comments.

Comments

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!

Comments

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();

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.