How can I achieve the same effect as Chrome (by setting or modifying some Chromium code)? Thank you very much.
Problem Description
When opening the same web page using the Chrome browser and the Android WebView, we noticed differences in handling the soft keyboard. When the soft keyboard pops up, the Chrome browser does not modify the size of the window. However, the Android WebView changes the window size. We hope to achieve the same effect as the Chrome browser in the Android WebView, that is, the window size does not change when the soft keyboard pops up. The following is detailed information about this issue:
Specific Situation
Test Environment:
Device: any android device
Android system version: andriod 15
Chrome browser version: 136/135/130
WebView version: 135
Web Page Content: A simple web page containing an input box. When the input box is clicked, the soft keyboard pops up.
Different Behaviors:
In the Chrome browser, when the soft keyboard pops up, the size of the web page window remains unchanged, the position of the input box is relatively fixed, and the content of the page will not be compressed or moved.
In the Android WebView, when the soft keyboard pops up, the size of the web page window changes. Usually, the height of the window decreases, part of the input box is blocked by the soft keyboard, and the content of the page may be compressed or rearranged.
Desired Implementation
We expect that in the Android WebView, when the soft keyboard pops up, the size of the web page window remains unchanged, the input box is not overly blocked by the soft keyboard, and the layout of the page content is stable, achieving the same display effect as the Chrome browser.
Attempted Solutions
We set the android:windowSoftInputMode="adjustPan" attribute in the Activity of the Android WebView. Although this can move the entire page up to avoid the input box being completely blocked, the window size still changes, which is not the desired effect.
Som android code:
layout->main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/webview_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout> MainActivity:class MainActivity : ComponentActivity() {
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.main)
val webView = findViewById<WebView>(R.id.webview)
webView.settings.javaScriptEnabled = true
webView.loadUrl("xxxxx")
webView.webViewClient = WebViewClient()
}
}
Android WebviewChrome
test html