Textbox hidden below keyboard in Android webview
This is how I solved the problem. As Venky said, you have to add
android:windowSoftInputMode="adjustResize"
to your tag in the AndroidManifest.xml file. But in our case, it wasn't enough. Make sure you do this as well with your views, webviews etc. Then we finally made it work.
Textbox hidden below keyboard in Android XWalkView or WebView
Instead of adding this
android:windowSoftInputMode="adjustPan"
you have use this
android:windowSoftInputMode="adjustResize"
Keyboard hiding text field from WebView
I removed Scrollview
and added:getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Now it's working
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(),
],
),
);
}
Android webview keyboard covering up input
Android has a keyboard event that I listen to. When the show/hide is trigger, I grab the active input component and transform the box in the y axis by the size of the keyboard height which can be grab from the event in the listener. I transform back when the show is triggered.
Note: resize needs to be disabled for the android:windowSoftInputMode and set to "adjustPan"
Related Topics
Android:Change Button Text and Background Color
Sqlite Query in Android to Count Rows
How to Search for a Value in Firebase Android
Page Scroll When Soft Keyboard Popped Up
Copy Database File to Sdcard in Android
Change Device Language via Adb
How to Use "Goasync" for Broadcastreceiver
How to Dynamically Change an App Icon Like Calendar App Does
Android - How to Intercept the 'Install Application' Intent
Clear Application Cache on Exit in Android
How to Import a .Aar File into Android Studio 1.1.0 and Use It in My Code