1

I looked it up many times and even changed the Code to something that should work (e.g. verified answer on stackoverflow), but it still doesn't work and I don't know why.

So I created a webView and want it to Display a page. I tried Google.com, but I only get a White space on the window where the webview lays (no Errors, just unclickable White space)

here's my Code:

Main Activity:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
       /*WebView wv = (WebView) findViewById(R.id.webview);
       wv.setWebViewClient(new MyBrowser());

        wv.loadUrl("http:\\www.google.com");
        */

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        if (navigationView != null) {
            navigationView.setNavigationItemSelectedListener(this);
        }

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame_main, new Home()).commit();
        WebView w = (WebView) findViewById(R.id.webview);
        w.getSettings().setJavaScriptEnabled(true);
        w.getSettings().setLoadWithOverviewMode(true);
        w.getSettings().setUseWideViewPort(true);
        w.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view,String url){
            view.loadUrl(url);
            return true;
            }
        });
        w.loadUrl("http://www.google.com");
    }

The commented thing was the other Option with same result

I am posting this whole thing here because I think it could maybe have something to do with the fact that I am running a sidebar activity with Fragments.

I also added the permission in manifest, please tell me why it's not working

PS: my phone has working Internet Connection

Here is my XML-File

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="myadress.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="400sp"
        android:id="@+id/webview"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">


    </WebView>

</android.support.constraint.ConstraintLayout>

activity main XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/frame_main"

        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

0 Answers0