原来的代码如下所示,但是一直展示空白页面。

private WebView webView ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_webview);
		this.webView=(WebView) this.findViewById(R.id.WebView);
		this.webView.getSettings().setSupportZoom(false);
//		this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		this.webView.getSettings().setJavaScriptEnabled(true);
		this.webView.getSettings().setDomStorageEnabled(true);
//		this.webView.loadUrl("http://weibo.cn/");
		
		webView.setWebViewClient(new WebViewClient(){   
		        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){   
		                  //handler.cancel(); 默认的处理方式,WebView变成空白页   
//		                  //接受证书   
		        	handler.proceed();
		                 //handleMessage(Message msg); 其他处理   
		       }
		 });
		
		this.webView.loadUrl("http://*.*.*.*:8080/html/hello.html");
		
	}
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
   <WebView android:id="@+id/WebView"
        android:layout_width="fill_parent" 
        android:layout_height="0dip"/>

</RelativeLayout>



修改方式:

<?xml version="1.0" encoding="UTF-8"?>
<AbsoluteLayout android:orientation="vertical" android:id="@+id/tab1" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <WebView android:id="@+id/WebView"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    	android:layout_x="0.0dip"
    	android:layout_y="0.0dip"
    	android:layout_weight="1.0" />
</AbsoluteLayout>




Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐