Android WebView demo
来源:互联网 发布:淘宝代理协议书 编辑:程序博客网 时间:2024/06/07 15:15
Android WebView的一个简单demo。
最终效果图:
AndroidManifest.xml中加访问INTERNET权限
<uses-permission android:name="android.permission.INTERNET"/>MainActivity
package com.example.shen.webviewdemo;import android.app.Activity;import android.os.Bundle;import android.view.KeyEvent;import android.webkit.WebView;import android.webkit.WebViewClient;public class MainActivity extends Activity { private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { String url = "http://bbs.meitiandian.com/plugin.php?id=wechat:access"; webView = (WebView) findViewById(R.id.webview); //启用支持JavaScript webView.getSettings().setJavaScriptEnabled(true); //启用支持DOM Storage webView.getSettings().setDomStorageEnabled(true); //加载web资源 webView.loadUrl(url); //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开 webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); } //改写物理按键的返回的逻辑 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { if (webView.canGoBack()) { webView.goBack();//返回上一页面 return true; } else { finish(); } } return super.onKeyDown(keyCode, event); }}activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="#0F0"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="WebViewDemo" android:layout_centerVertical="true" android:layout_marginLeft="5dp"/> </RelativeLayout> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/hello_world" /></LinearLayout>demo下载地址:http://download.csdn.net/download/shenyuanqing/9177165
0 0
- Android:+WebView+demo
- Android WebView Demo
- Android WebView demo
- Android WebView与服务端交互Demo
- Android demo-->webview实现js交互
- WebView Demo
- Android WebView与JavaScript交互操作(Demo)
- 【android】带加载进度条的WebView (附demo下载)
- WebView的Demo
- WebView小Demo
- webview demo apk 下载
- WebView 控件使用Demo
- WebView.loadData()Demo
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- Chrome和FF无法关联JRE的问题解决
- Java并发编程:线程池的使用
- linux signal函数使用
- Centos 6.5 CM5.3.2和CDH5.3.2安装
- SharePoint 2013 IT Professional-- Managed Metadata Service之Content type Hub
- Android WebView demo
- android 支付宝支付
- WebView的简单使用及和js的交互
- node.js资料
- CI框架获取url中的参数
- thymeleaf 学习笔记
- jQuery源码分析之prop和removeProp方法
- 关于URL编码/javascript/js url 编码/url的三个js编码函数
- 个人学习——网络:根据子网掩码计算子网数