您的位置:首页 > 移动开发 > Android开发

Android的webview加载本地html、本apk内html和远程URL

2016-03-23 18:01 633 查看
转自:/article/7842187.html

首先在layout文件夹下的xml中 加入WebView控件

[xhtml] view
plain copy

<WebView

android:id="@+id/wv1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

再在主文件中输入如下代码

[java] view
plain copy

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");

}

}

-----打开本包内asset目录下的index.html文件

//wView.loadUrl("file:///android_asset/index.html");

-----打开本地sd卡内的index.html文件

//wView.loadUr("content://com.android.htmlfileprovider/sdcard/index.html");

-----打开指定URL的html文件

//wView.loadUrl("http://wap.baidu.com");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: