I am trying to implement a WebView in one one of my xml files in my android studios mobile app project. What I am trying to do is have a few buttons that will navigate through different pages that are local to the app, and have a webpage beneath those buttons. However, the webview keeps taking up the entire screen space and the buttons that I created can no longer be seen. For reference, here is the 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"
android:background="#ffffff"
tools:context=".GetInvolved" >
<Button
android:id="@+id/homeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="51dp"
android:adjustViewBounds="true"
android:background="@android:color/black"
android:clickable="false"
android:onClick="goHome"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/webView"
android:layout_width="408dp"
android:layout_height="572dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/homeButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
And here is how I'm loading the webview
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
view = findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient() {
@Override
public void onLoadResource(WebView webView, String url) {
try {
// remove the nav bar and the footer from each loaded page.
view.loadUrl("javascript:(window.onload = function() { " +
"})()");
} catch (Exception e) {
e.printStackTrace();
}
}
});
view.loadUrl("https://www.google.com/");
}
I have tried several different Stack Overflow posts like this one Webview is taking fullscreen in android but I could not get it to work. Any help is appreciated, thank you.