Android : Form in Android webview not responding to keyboard on HTC One

on Tuesday, March 24, 2015


This is a bit of a strange one.


We had a bug report that when people used an HTC One phone they couldn't type into the login text boxes of our android app.


The login view is just a webview that is in a fragment loaded into an activity. The website called by the webview has a standard html form in it.


I created the simplest of test applications to see whether I could pinpoint what was happening,(and ruling out anything quirky in our codebase).


The test just has a webview, (in a fragment), calling a webpage that displays a simple form. When you click on the input of the form the keyboard appears. Any keys that are then pressed are not registered and the inputs remain blank even though they have focus.


Here is my Activity:



public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}

public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
WebView webView = (WebView) rootView.findViewById(R.id.login_webview);

webView.loadUrl("*<my test url here>*");

return rootView;
}
}


}


Here are my layout files: Activity:



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame" />


fragment:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">


<uk.ac.gre.htconetest.LoginWebView
android:windowSoftInputMode="adjustResize"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/login_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />


My webview class:



public class LoginWebView extends WebView {
public LoginWebView(Context context) {
super(context);
}

public LoginWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public LoginWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
public boolean onCheckIsTextEditor() {
return true;
}


}


My test webpage:



<html>
<head></head>
<body>
<h1>hello</h1>
<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
</body>
</html>


The Phone is running :


Android 4.2.2,

HTC Sense 5.0,

HTC SDK Api Level 5.4.1


I would appreciate any ideas.


Many Thanks, m


0 comments:

Post a Comment