android开发中WebView的使用(附完整程序)
WebView是个好东西,作用相当于一个迷你的浏览器,采用Webkit内核,因此完美支持html,javascript,css等。有时候,我们完全可以把UI甚至数据处理都交给WebView,配合PHP等服务端程序,这样Android开发就变成了网页开发,可以省很多精力。
下面是一个WebView的简单例子,如果用把所有功能都交给服务端脚本处理,这个程序已经很完整了,你只要写好网页,把URL填上,再编译,就是一个新软件。
程序功能介绍:打开网页同时显示一个ProgressDialog,网页载入完毕则隐藏,点击页面上链接时再次显示ProgressDialog,载入完隐藏,可用返回键返回上一页。
XML布局:
1 2 3 4 5 6 7 8 9 10 | <?xml version="1.0" encoding="UTF-8"?> <AbsoluteLayout android:orientation="vertical" android:id="@+id/tab1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <WebView android:id="@+id/wv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_x="0.0dip" android:layout_y="0.0dip" android:layout_weight="1.0" /> </AbsoluteLayout> |
JAVA代码:
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |