我对Android工作室很新,我正面临这个问题,我已经采用其他代码在我的片段中应用webview,目前我的webview在模拟器上测试时显示的是空白页而不是我的网址设置。非常适合你的帮助:)
xml和java如下
xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseParallaxMultiplier="1.0">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Java
public class FavoritesFragment extends Fragment {
WebView myWebView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.favorites,container,false);
myWebView = (WebView) view.findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.google.com");
myWebView.setWebViewClient(new WebViewClient());
return view;
}
}