Ich habe mich auf dieser Seite umgesehen und gegoogelt, aber ich fürchte, ich stecke fest. Ich kann einfach kein Webview für mein Fragment erstellen. Ich habe hier viel Code ausprobiert, aber da muss etwas fehlen.Webview zum Arbeiten in einem Fragment
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="layout.GER1">
<WebView
android:id="@+id/webview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</WebView>
</RelativeLayout>
Java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.example.a1cmanny1.bmi.R;
public class GER1 extends Fragment {
public WebView mWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_ger1, container, false);
mWebView = (WebView) v.findViewById(R.id.webview);
mWebView.loadUrl("https://www.google.co.nz/");
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
return v;
}
}
Jede Hilfe würde geschätzt.
Alles in Ihrem Code sieht gut aus. Was ist das Problem, vor dem Sie stehen? –
Die Webansicht ist nur leer, wenn ich es ausführe. Es versucht nicht einmal und lädt. Möglicherweise habe ich etwas von der Aktivität verpasst, die das Webview im Fragment ermöglicht? – 1cmanny1
Ich verwende auch die Registerkarte Aktivität - Swipe-Ansicht Vorlage. Ich habe die in der Manifestdatei. –
1cmanny1