Website menu bar not working with WebView android while working fine in mobile browser

Viewed 4203

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 URL open in android webview

When opening in mobile browser

When opening in mobile browser in

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!

3 Answers

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.

works for me by adding these two lines:

mywebView.getSettings().setDomStorageEnabled(true);
mywebView.getSettings().setJavaScriptEnabled(true);

Yes, I have the same problem and by adding these lines of code its working perfectly.

public class MainActivity extends AppCompatActivity {
    private WebView websiteView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        websiteView = (WebView) findViewById(R.id.websiteview);
        WebSettings webSettings = websiteView.getSettings();
        websiteView.getSettings().setDomStorageEnabled(true);
        websiteView.getSettings().setJavaScriptEnabled(true);
        webSettings.setJavaScriptEnabled(true);
        websiteView.loadUrl("https://abdulrahmanayub.com/");
        websiteView.setWebViewClient(new WebViewClient());

    }
}
Related