网站菜单栏不适用于 WebView android,而在移动浏览器中工作正常 [英] Website menu bar not working with WebView android while working fine in mobile browser

查看:26
本文介绍了网站菜单栏不适用于 WebView android,而在移动浏览器中工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 WebView 并使用 WebView android 打开一个网站.网站的菜单栏在移动浏览器中工作正常,但是当我在 WebView android 中打开 URL/网站时,菜单栏不起作用.

在 Android WebView 中打开时(菜单栏不响应)

在移动浏览器中打开时

中的移动浏览器中打开时

下面是我用来在 WebView 中打开 URL 的代码:

WebView mWebView = (WebView) findViewById(R.id.webview);WebSettings mWebSettings = mWebView.getSettings();mWebSettings.setJavaScriptEnabled(true);mWebSettings.setSupportZoom(false);mWebView.setWebViewClient(new WebViewClient());mWebView.setWebViewClient(new WebViewClient() {public boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);返回真;}public void onPageFinished(WebView view, String url) {}public void onReceivedError(WebView view, int errorCode, String descripti0on, String failedUrl) {}});mWebView.loadUrl("https://www.buyvipgift.com");

请告诉我哪里出错了!

解决方案

我在代码中添加了 mWebSettings.setDomStorageEnabled(true) 这一行,现在工作正常.

setDomStorageEnabled(boolean flag)

设置是否启用 DOM 存储 API.

因为登陆页面提供了可用于自定义颜色字体装饰图像的控件.当您选择不同的选项时,页面会立即更新;此外,您的选择存储在 localStorage 中,以便在您离开页面时再次加载它,以便记住您的选择.

此外,如果您在另一个选项卡中加载此页面,然后在登录页面中更改您的选择,您将看到更新的存储信息在 StorageEvent 被触发时输出.>

I'm working on WebView and opening a website using WebView android. The menu bar of the website is working fine in the mobile browser but when I open the URL/website in WebView android then menu bar doesn't work.

When open in Android WebView (Menu-bar don't respond)

When opening in mobile browser

Below is the code that I'm using to open the URL in WebView:

WebView mWebView = (WebView) findViewById(R.id.webview);
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebSettings.setSupportZoom(false);

mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebViewClient(new WebViewClient() {
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
  view.loadUrl(url);
  return true;
 }

 public void onPageFinished(WebView view, String url) {

 }

 public void onReceivedError(WebView view, int errorCode, String descripti0on, String failingUrl) {

 }
});

mWebView.loadUrl("https://www.buyvipgift.com");

Please let me know where I'm going wrong!

解决方案

I added mWebSettings.setDomStorageEnabled(true) this line in my code and it's working fine now.

setDomStorageEnabled(boolean flag)

Sets whether the DOM storage API is enabled.

Because, the landing page provides controls that can be used to customize the colour, font and decorative image. When you choose different options, the page is instantly updated; in addition your choices are stored in localStorage, so that when you leave the page then load it again later on your choices are remembered.

In addition, if you load this page in another tab, then make changes to your choices in the landing page, you'll see the updated storage information outputted as the StorageEvent is fired.

这篇关于网站菜单栏不适用于 WebView android,而在移动浏览器中工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆