首先在layout文件夹下的xml中 加入WebView控件
- <WebView
- android:id="@+id/wv1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
再在主文件中输入如下代码
- public class TestDemo extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- WebView wView = (WebView)findViewById(R.id.wv1);
- WebSettings wSet = wView.getSettings();
- wSet.setJavaScriptEnabled(true);
- //wView.loadUrl("file:///android_asset/index.html");
- //wView.loadUrl("content://com.android.htmlfileprovider/sdcard/index.html");
- wView.loadUrl("http://wap.baidu.com");
- }
- }
//wView.loadUrl("file:///android_asset/index.html");
-----打开本包内asset目录下的index.html文件
//wView.loadUrl("content://com.android.htmlfileprovider/sdcard/index.html");
-----打开本地sd卡内的index.html文件
//wView.loadUrl("http://wap.baidu.com");
-----打开指定URL的html文件
转载地址:http://blog.csdn.net/windone0109/article/details/5380941