Activity:
public class CourseOnLine extends Activity {
private WebView webview;
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
showDialog(0);
super.onCreate(savedInstanceState);
setContentView(R.layout.online);
Intent intent=getIntent();
Bundle data=intent.getExtras();
String courseURL=data.getString("courseWebURL");
webview=(WebView)findViewById(R.id.webview01);
//设置WebView属性,能够执行JavaScript脚本
webview.getSettings().setJavaScriptEnabled(true);
//如果要播放Flash,需要加上这一句
webview.getSettings().setPluginsEnabled(true);
//加载URL内容
webview.loadUrl(courseURL);
MyWebViewClient myWebView=new MyWebViewClient();
webview.setWebViewClient(myWebView);
}
@Override//设置回退
public boolean onKeyDown(int keyCode, KeyEvent event) {
if((keyCode==KeyEvent.KEYCODE_BACK) && webview.canGoBack()){
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected Dialog onCreateDialog(int id) {
//实例化进度条对话框
dialog=new ProgressDialog(this);
/*//可以不显示标题
dialog.setTitle("正在加载,请稍候!");*/
dialog.setIndeterminate(true);
dialog.setMessage("正在加载,请稍候!");
dialog.setCancelable(true);
return dialog;
}
private class MyWebViewClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
dialog.dismiss();
}
}
layout:online.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
分享到:
相关推荐
android webview 顶部进度条+旋转等待dialog例子、可直接运行。
android webview 因iframe+target=“_blank “ 导致的页面无法正常打开或获取不到调整url
android webView+progressBar刷新加载示例.有需要的可以自行下载查看
android通过webview加载html,调用js获取摄像头拍照保存图片,程序已调试运行成功,androidStudio导入运行即可
Android中WebView与HTML+Javascript的交互 Android中WebView与HTML+Javascript的交互
图片列表RecyclerView+ListView+WebView+JzvdStdJZPlayer+Jsoup+Glide(二)
集成webview+gps+相机调用的安卓app源码,很有实际应用框架。
实现webview加载时显示进度条,类似微信公众号文章加载。
WebView进度条实例:Webview根据加载程度决定进度条的进度大小,当加载到100%的时候 进度条自动消失
这是AOSP Webview, 包名com.android.webview, 不带google的 带google包名的可以下载 google system webview覆盖安装,可以略过 此文件包含 arm和arm64的webview
NULL 博文链接:https://1136051009.iteye.com/blog/1844627
能根据webView加载的内容,动态的显示进度。 对NJKWebViewProgress的再次运用 NJKWebViewProgress下载地址:https://github.com/ninjinkun/NJKWebViewProgress
安卓仿微信webview进度条,微信打开网页时,上方的绿色进度条。样式与速度都一样哟!!!微信打开网页时,上方的绿色进度条。
项目中用到WebView加上进度条放在顶部,让用户知道加载进度情况,可以提高用户体验: 效果: 布局: android:layout_height=match_parent android:orientation=vertical> <WebView android:id=@+id/...
主要为大家详细介绍了Android中WebView加载网页设置进度条的相关代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
WebView顶部平滑进度条(仿微信效果)
WebView的使用,加载时添加进度条类型微信开发网页;
推荐阅读:Android WebView线性进度条实例详解 最近在android项目中使用webview嵌套了一个抽奖活动网页,活动上线,运行良好(改了N次需求和突发bug),还好这种模式的活动,只需要修改网页,不需要重新打包发布市场...
webView登陆小例子