'Why Android Webview website menu doesn't load?
I'm working on an app that is mainly a WebView, as the main function of it is to display a website plus some other options I've yet to add.
The problem comes with the WebView, as it doesn't show the website menus. I've seen it's a common issue, and I've tried all the answers I've found, but none of them seems to work.
I've tried to run it in both api 30 and 26, it happens in both of them
Here you have the code for the activity:
package com.example.notificationtest;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView=(WebView) findViewById(R.id.webView);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setUseWideViewPort(true);//setting wide view
webView.getSettings().setLoadWithOverviewMode(true);//setting default zoomed out view
webView.setInitialScale(1);
webView.getSettings().setBuiltInZoomControls(true);//setting zoom controls
//webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("https://desdelsofa.cat");
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.ic_launcher);
}
}
Its .xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Just to add some more fun, I've been trying other sites, and somehow, it seems to render the side menu. I guess it's because of the website code, but when using the phone web navigation, it works fine.
This is how it should look
And this is how it looks
Solution 1:[1]
So, somehow, I've found a tutorial I hadn't seen before, and it seems to work just perfect. Here you have the link https://www.c-sharpcorner.com/article/create-web-browser-android-application-using-android-studio/
IMPORTANT: It uses an old version of SwipeLayoutRefresh, take care of using androidx.swiperefreshlayout.widget.SwipeRefreshLayout insted of android.support.v4.widget.SwipeRefreshLayout as seen in the tutorial.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Llop Roig |


