[笔记] Android WebView使用方法
来源:互联网 发布:阿里云虚拟主机代理 编辑:程序博客网 时间:2024/04/28 15:19
WebView webView = (WebView) findViewById(R.id.webview);
// webView.evaluateJavascript(script, resultCallback);
// 添加js调用的android接口
// webView.addJavascriptInterface(new WebAppInterface(this), "Android");
// 设定自定义导航WebClient, 可以通过判断url完成打开Activitty;
// webView.setWebViewClient(new MyWebViewClient());
// 设定自定义WebChromeClient, 可以获取加载进度;
// webView.setWebChromeClient(new MyWebChromeClient());
WebSettings webSettings = webView.getSettings();
// 启用js
webSettings.setJavaScriptEnabled(true);
// 设置可以自动加载图片
webSettings.setLoadsImagesAutomatically(true);
// 加载asset下的html
webView.loadUrl("file:///android_asset/paper/index.html");
//--------------------WebAppInterface.java---------------------------------------------------------
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
// 设定webview背景透明
webView.setBackgroundColor(0x00FFFFFF);
webView.getBackground().setAlpha(0);
// webView.evaluateJavascript(script, resultCallback);
// 添加js调用的android接口
// webView.addJavascriptInterface(new WebAppInterface(this), "Android");
// 设定自定义导航WebClient, 可以通过判断url完成打开Activitty;
// webView.setWebViewClient(new MyWebViewClient());
// 设定自定义WebChromeClient, 可以获取加载进度;
// webView.setWebChromeClient(new MyWebChromeClient());
WebSettings webSettings = webView.getSettings();
// 启用js
webSettings.setJavaScriptEnabled(true);
// 设置可以自动加载图片
webSettings.setLoadsImagesAutomatically(true);
// 加载asset下的html
webView.loadUrl("file:///android_asset/paper/index.html");
//--------------------WebAppInterface.java---------------------------------------------------------
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
0 0
- [笔记] Android WebView使用方法
- Android开发笔记: WebView的使用方法
- android webView 使用方法
- android webView的使用方法
- android webView 使用方法
- android webView使用方法二
- android webView使用方法
- android webView使用方法
- Android WebView使用方法
- android开发android webView 使用方法
- Android WebView的简单使用方法
- Android webview的基本使用方法
- android webview的常见使用方法
- Android中WebView的使用方法
- android开发之android webView使用方法
- Android WebView学习笔记
- WebView使用笔记 Android
- Android WebView 笔记
- unity3D物体的旋转和缩放
- block及arc中注意事项
- UVA - 12335 Lexicographic Order (第k大排列)
- oracle
- 键盘控制div移动
- [笔记] Android WebView使用方法
- structs2中interceptor(拦截器)的种类
- Linux scp 命令使用详解
- eclipse插件spket安装
- 关于各种码--ASCII--Unicode--UTF-8/16/32
- renderlayerbacking
- service之一
- 戴维解惑——用iTestin云测做测试怎样拿大奖
- BlueStacks 使用说明