//在布局中建立一个WebView控件
public class WebActivity extends Activity {
private WebView mywebview;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_web);
String url ="http://www.baidu.com";
mywebview.getSettings().setJavaScriptEnabled(true);
mywebview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mywebview.loadUrl(url);
//在webview没有加载出来时显示一个加载框
if (mywebview != null) {
mywebview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressDialog.dismiss();
}
});
initVIew(url);
}
}
private void initVIew(String uri) {
if (mywebview != null) {
progressDialog = ProgressDialog.show(WebActivity.this, "加载", "正在加载,请稍候!", true);
mywebview.loadUrl(uri);
}
}
//得到控件ID
public void infoview() {
mywebview = (WebView) findViewById(R.id.mywebview);
}
}
在应用内部打开WebView
最新推荐文章于 2022-10-10 09:57:09 发布