自己新建一个项目弄弄吧:
activity:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
public
class
School_ggtz
extends
Activity {
private
WebView webView;
private
String url;
private
ImageView iv_school_title;
private
TextView tv_school_content;
private
ProgressDialog dialog;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_school_xxgk);
iv_school_title = (ImageView) findViewById(R.id.iv_school_title);
iv_school_title.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View arg0) {
finish();
}
});
tv_school_content = (TextView) findViewById(R.id.tv_school_content);
tv_school_content.setText(getResources().getString(
R.string.school_ggtz_content));
webView = (WebView) findViewById(R.id.id_webview);
url = getResources().getString(R.string.school_ggtz);
webView.loadUrl(url);
webView.setWebViewClient(
new
WebViewClient() {
@Override
public
boolean
shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return
true
;
}
});
WebSettings settings = webView.getSettings();
settings.setSupportZoom(
true
);
settings.setBuiltInZoomControls(
true
);
settings.setDisplayZoomControls(
false
);
// 隐藏webview缩放按钮
settings.setUseWideViewPort(
true
);
settings.setLoadWithOverviewMode(
true
);
settings.setJavaScriptEnabled(
true
);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.setWebChromeClient(
new
WebChromeClient() {
@Override
public
void
onProgressChanged(WebView view,
int
newProgress) {
// TODO Auto-generated method stub
// newProgress 1-100之间的整数
if
(newProgress ==
100
) {
// 网页加载完毕,关闭ProgressDialog
closeDialog();
}
else
{
// 网页正在加载,打开ProgressDialog
openDialog(newProgress);
}
}
private
void
closeDialog() {
// TODO Auto-generated method stub
if
(dialog !=
null
&& dialog.isShowing()) {
dialog.dismiss();
dialog =
null
;
}
}
private
void
openDialog(
int
newProgress) {
// TODO Auto-generated method stub
if
(dialog ==
null
) {
dialog =
new
ProgressDialog(School_ggtz.
this
);
dialog.setTitle(
"正在加载"
);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(newProgress);
dialog.show();
}
else
{
dialog.setProgress(newProgress);
}
}
});
}
}
|
xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/white"
android:orientation=
"vertical"
>
<include layout=
"@layout/activity_school_title"
/>
<WebView
android:id=
"@+id/id_webview"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:scrollbars=
"none"
/>
</LinearLayout>
|
效果图:PS:可以缩放,并且支持双击Max,支持脚本。
本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1604052,如需转载请自行联系原作者