Jeeva
Jeeva

Reputation: 4825

jQuery .focus() not working in Android webview

I am trying to focus the input field on page loaded, so I used $(selector).focus() after the content loaded. It working on desktop and chrome browser in Android, but when I load the same page in a webview in Android, it's not working.

I googled about this focus issue, I found couple attributes for webview so I added them, but still it's not working

<WebView
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:layout_weight="1"
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="0dp" />

Note: The webview is inside a bottom sheet fragment.

Upvotes: 0

Views: 1120

Answers (1)

Lin
Lin

Reputation: 59

try this

webview.getsettings().setjavascriptenabled(true);

update

//add this before you webview load url
webview.requestFocus();

Upvotes: 1

Related Questions