Hello,
You can do it by handler for webview. I add webview handler in the page's background code.
Then you can use Conditional compilation for android platform achievement.
You can refer to the following code.
public MainPage()
{
InitializeComponent();
Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
if (view is CustomWebView)
{
#if ANDROID
CustomWebView customWebView=view as CustomWebView;
handler.PlatformView.SetWebViewClient(new XamWebViewClient(customWebView));
#endif
}
});
}
#if ANDROID
public class XamWebViewClient : Android.Webkit.WebViewClient
{
private CustomWebView _customwebView;
public XamWebViewClient(CustomWebView _customwebView)
{
this._customwebView = _customwebView;
}
/// <summary>
/// OnPageFinished
/// </summary>
/// <param name="view"></param>
/// <param name="url"></param>
public override async void OnPageFinished(Android.Webkit.WebView? view, string? url)
{
if (_customwebView != null)
{
int i = 10;
await System.Threading.Tasks.Task.Delay(200);// The time here can be adjusted
_customwebView.HeightRequest = view.ContentHeight;
}
}
}
#endif
Best Regards, Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.