[笔记] Android WebView使用方法
2014-08-14 11:41
543 查看
WebView webView = (WebView) findViewById(R.id.webview);
// 设定webview背景透明
webView.setBackgroundColor(0x00FFFFFF);
webView.getBackground().setAlpha(0);
// 执行javascript方法
// 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);
// 执行javascript方法
// 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();
}
}
相关文章推荐
- Android开发笔记: WebView的使用方法
- android webView使用方法二
- android开发之android webView使用方法
- Android WebView的使用方法总结
- 使用chrome查看Android webView各个元素的控件方法
- android webview中使用Java调用JavaScript方法并获取返回值
- android开发android webView 使用方法
- 使用webView中的javaScript调用Android方法
- android webView使用方法
- Android WebView 使用笔记
- Android使用WebView播放flash的方法
- Android编程 - WebView控件基本使用方法
- android webView 使用方法
- Android使用WebView无法定位问题的解决方法
- Android使用原生组件WebView加载网页和数据的方法
- android开发之android webView使用方法
- android上不使用qq的SDK,用WebView登陆qq的方法。
- android webView 使用方法
- android webView 加载HTML代码使用loadData方法中文乱码问题
- android 学习笔记3——WebView的使用