Tapping Form Field in Webview Does Not Show Soft Keyboard

Tapping form field in WebView does not show soft keyboard

http://code.google.com/p/android/issues/detail?id=7189

Here is a fix in case other were not clear.

    webview.requestFocus(View.FOCUS_DOWN);
webview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});

Flutter webview text input gets hidden by soft keyboard

The answer for me was two things.

First to use this line which sets WebView.platform inside the stateful widget showing the webview. Notice that it's specific to my testing at the time on Android, so perhaps for some of you when you didn't see the issue, you maybe were on iOS?

  @override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); // <<== THIS
}

Second I added a Scaffold with resizeToAvoidBottomInset set to true and removed my use of this:

height: MediaQuery.of(context).size.height * (MediaQuery.of(context).viewInsets.bottom != 0 ? .7 : 1),`

Here is the code for the body with the webview

@override
Widget build(BuildContext context) {
return SafeArea(
child: Stack(
children: [
initialUrl == null
? Container()
: Scaffold(
resizeToAvoidBottomInset: true,
body: WebView(
initialUrl: initialUrl,
javascriptMode: JavascriptMode.unrestricted,
onPageStarted: (controller) {},
onPageFinished: (controller) {
Future.delayed(Duration(milliseconds: 1234), () {
if (mounted) {
showLoading = false;
setState(() {});
}
});
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://example.com/success')) {
Navigator.of(context).pop('success');
} else if (request.url.startsWith('https://example.com/cancel')) {
Navigator.of(context).pop('cancel');
}
return NavigationDecision.navigate;
},
),
),
showLoading == true
? Center(
child: Container(width: 80, height: 80, child: CircularProgressIndicator()),
)
: Container(),
],
),
);
}

Soft Keyboard not displaying on touch in WebView DialogFragment

This is a system bug that has not yet been fixed. More information can be found here. It seems as though this bug occurs differently for people and therefore has different solutions. For my particular case, there is only one solution (as I've tried everything else). Solution:

First, I created a layout for the Dialog:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:visibility="invisible"/>

<WebView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>

Then, in the DialogFragment class in the onCreateDialog method:

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = LayoutInflater.from(getActivity());
View v = inflater.inflate(R.layout.internet_dialog, null);

WebView web = (WebView) v.findViewById(R.id.web);
EditText edit = (EditText) v.findViewById(R.id.edit);
edit.setFocusable(true);
edit.requestFocus();
web.loadUrl(url);
this.webView = web;
builder.setView(v);

return builder.create();

And that's all there was to it. The reason this worked was because I made an EditText which I gave the focus to yet made invisible. Since the EditText is invisible it doesn't interfere with the WebView and since it has focus it pulls the soft keyboard up appropriately. I hope this helps any stuck in a similar situation.

Android soft Keyboard not open in webView`

Here is my solution to this problem:

Put a dummy edit text, and set it's visibility to GONE, and add it to a containing LinearLayout, after adding the WebView to the layout.

Example:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

LinearLayout wrapper = new LinearLayout(this);
WebView webView = new WebView(this);
EditText keyboardHack = new EditText(this);

keyboardHack.setVisibility(View.GONE);

webView.loadUrl(url);

wrapper.setOrientation(LinearLayout.VERTICAL);
wrapper.addView(webView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

builder.setView(wrapper);

builder.create().show();

Once this is done, everything should work properly, and when you select an item in the WebView, the keyboard appears as expected.

android webview keyboard doesn't appear for long time to input values

I found the solution for my problem, It's pretty specific though, I hope it will help someone sometime...

I extendedWebViewClient, and overrode few of its functions.
my issue started when I loaded a propitiatory javascript: on onLoadResource(). For some reason, doing so caused the whole keyboard abnormality. I moved the script to run on onPageFinished() and the WebView acts normally again.



Related Topics



Leave a reply



Submit