A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hi @EL CARU Caruso ,
Thanks for reaching out.
From the log you shared, this is happening because MAUI webview is not a real chrome tab, it’s a web page sitting inside your app, and Android doesn’t always “make room” for the keyboard the way Chrome does.
a. Is there a recommended way in .NET MAUI to handle the Android soft keyboard with WebView?
You may refer to this way below:
This is the basic setting that stops the keyboard from sitting on top of your WebView.
In MAUI, this is the AdjustResize setting.
public App()
{
InitializeComponent();
MainPage = new MainPage();
Current.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
b. Should this be fixed on the MAUI side (windowSoftInputMode / platform-specific code) or via CSS/JavaScript inside the page?
I would recommend doing these:
- Fixed on the MAUI side is the baseline. It prevents the keyboard from simply overlapping the WebView.
- Via Css/JS inside the page is what prevents the “jump too far / huge empty space” problem. A lot of chat layouts use things like height: 100vh or fixed bottom bars, and those don’t always behave well inside an embedded WebView when the viewport height changes. So set AdjustResize first, then fine-tune the chat page with CSS/Js so the input stays sitting nicely just above the keyboard.
c. How can I properly inject JavaScript into the MAUI WebView to handle viewport/keyboard resizing?
In .NET MAUI, you can inject JavaScript into a WebView using the EvaluateJavaScriptAsync method (for one-way execution).
Ex: WebView using the EvaluateJavaScriptAsync method
using Microsoft.Maui.Controls;
webView.Navigated += async (_, __) =>
{
var js = @"
(function () {
if (window.__kbFix) return; window.__kbFix = true;
function pad() {
var full = window.innerHeight;
var vv = window.visualViewport ? window.visualViewport.height : full;
var kb = Math.max(0, full - vv);
document.body.style.paddingBottom = kb + 'px';
}
document.addEventListener('focusin', function () {
setTimeout(function () {
var el = document.activeElement;
if (el && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable)) {
el.scrollIntoView({ block: 'center' });
}
pad();
}, 50);
});
if (window.visualViewport) window.visualViewport.addEventListener('resize', pad);
window.addEventListener('resize', pad);
pad();
})();";
await webView.EvaluateJavaScriptAsync(js);
};
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well. Thanks for your time.