2011-06-28 55 views

回答

0

在佈局文件夾

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white"> 

     <WebView android:id="@+id/wv1" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:background="@color/white" /> 

     <WebView android:id="@+id/wv2" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:background="@color/white"/> 

    </FrameLayout> 

在活動

final String mimeType = "text/html"; 
final String encoding = "utf-8"; 
String nBody = "PUT YOUR HTML HERE" ; 
WebView wv1 = (WebView)findViewById(R.id.wv2); 
wv1.setBackgroundColor(Color.WHITE); 
wv1.setInitialScale(65); 
WebSettings webSettings1 = wv1.getSettings(); 
webSettings1.setUseWideViewPort(true); 
webSettings1.setDefaultFontSize(12); 
wv1.loadDataWithBaseURL(null, nBody, mimeType, encoding, null); 
0

在res文件夾創建一個XML創建一個XML文件中,res文件夾聲明有你的WebView

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@color/white"> 
    <WebView android:id="@+id/web" android:layout_height="fill_parent" 
     android:layout_width="fill_parent" android:background="@color/white" /> 
</FrameLayout> 

然後在你的活動中:

WebView wv1 = (WebView)findViewById(R.id.web); 
wv1.loadDataWithBaseURL(null, "HTML String", mimeType, encoding, null); 
相關問題