0
我想在webview下打开url。我有下面的代码:webview不显示正确
public class FragmentWebView extends Fragment {
TextView webview_bar_title;
ImageButton menu;
WebView wv;
public FragmentWebView() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_webview, container,
false);
menu = (ImageButton) view.findViewById(R.id.webview_menu);
menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity) getActivity()).onBackPressed();
}
});
webview_bar_title = (TextView) view.findViewById(R.id.webview_share);
webview_bar_title.setText("Share");
wv = (WebView) view.findViewById(R.id.fragment_webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://www.google.com");
return view;
}
}
而且这里是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/webview_actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/webview_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_left" />
<TextView
android:id="@+id/webview_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" />
</RelativeLayout>
<WebView
android:id="@+id/fragment_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/webview_actionbar" />
</RelativeLayout>
我想在我的WebView加载谷歌网页。但它不起作用,并给我错误,如网站不可用。 Google网页可能会暂时关闭,或者它可能已永久移动到新地址。和建议?提前致谢。
你有连接到互联网? – 2014-08-31 01:22:14
是的,我喜欢。这是模拟器的问题吗? – Shumin 2014-08-31 01:27:11
尝试使用仿真器中的默认网络浏览互联网,并参阅 – 2014-08-31 01:28:30