Android加載網頁WebView

測試功能直接在oncreate方法裏面調用了下面兩句代碼

setContentView(R.layout.main);
        setWebs();


 public void setWebs(){
    wv= (WebView) findViewById(R.id.web);
    WebSettings ws = webview.getSettings();
    //加載WebView一定要加上,能夠執行Javascript腳本    
    ws.setJavaScriptEnabled(true);    
        //可以訪問文件  
    ws.setAllowFileAccess(true);  
         //支持縮放  
    ws.setBuiltInZoomControls(true);     
        wv.loadUrl("http://hao123.com");    
        //設置Web視圖    
        wv.setWebViewClient(new webViews());    
    }
    //Web視圖    
    private class webViews extends WebViewClient {    
        public boolean shouldOverrideUrlLoading(WebView view, String url) {    
            view.loadUrl(url);    
            return true;    
        }    
    } 



佈局文件中寫個標籤就ok了

 <WebView android:id="@+id/web"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章