<uses-permission android:name="android.permission.INTERNET" />
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.widget.AbsoluteLayout
↳ android.webkit.WebView
|
WebSettings
|
getSettings()
获取设置WebView的WebSettings对象。
|
|
void
|
setWebViewClient(WebViewClient client)
设置将接收各种通知和请求的WebViewClient。
|
|
void
|
setWebChromeClient(WebChromeClient client)
设置chrome处理。
|
|
[b]方法[/b]
|
[b]说明[/b]
|
|
[b]setAllowFileAccess[/b]
|
启用或禁用WebView访问文件数据
|
|
[b]setBlockNetworkImage[/b]
|
是否显示网络图像
|
|
[b]setBuiltInZoomControls[/b]
|
设置是否支持缩放
|
|
[b]setCacheMode[/b]
|
设置缓冲的模式
|
|
[b]setDefaultFontSize[/b]
|
设置默认的字体大小
|
|
[b]setDefaultTextEncodingName[/b]
|
设置在解码时时候用的默认编码
|
|
[b]setFixedFontFamily[/b]
|
设置固定使用的字体
|
|
[b]setJavaScriptEnabled[/b]
|
设置是否支持Javascript
|
|
[b]setLayoutAlgorithm[/b]
|
设置布局方式
|
|
[b]setLightTouchEnabled[/b]
|
设置用鼠标激活被选项
|
|
[b]setSupportZoom[/b]
|
设置是否支持变焦
|
|
[b]方法[/b]
|
[b]说明[/b]
|
|
[b]doUpdateVisitedHistory[/b]
|
更新历史记录
|
|
[b]onFormResubmission[/b]
|
应用程序重新请求网页数据
|
|
[b]onLoadResource[/b]
|
加载指定地址提供的资源
|
|
[b]onPageFinished[/b]
|
网页加载完毕
|
|
[b]onPageStarted[/b]
|
网页开始加载
|
|
[b]onReceivedError[/b]
|
报告错误信息
|
|
[b]onScaleChanged[/b]
|
WebView发生改变
|
|
[b]shouldOverrideUrlLoading[/b]
|
控制新的连接在当前WebView中打开
|
|
[b]方法[/b]
|
[b]说明[/b]
|
|
[b]onCloseWindow[/b]
|
关闭WebView
|
|
[b]onCreateWindow[/b]
|
创建WebView
|
|
[b]onJsAlert[/b]
|
处理Javascript中的Alert对话框
|
|
[b]onJsConfirm[/b]
|
处理Javascript中的Confirm对话框
|
|
[b]onJsPrompt[/b]
|
处理Javascript中的Prompt对话框
|
|
[b]onProgressChanged[/b]
|
加载进度条改变
|
|
[b]onReceivedlcon[/b]
|
网页图标更改
|
|
[b]onReceivedTitle[/b]
|
网页Title更改
|
|
[b]onRequestFocus WebView[/b]
|
显示焦点
|
// Let's display the progress in the activity title bar, like the
// browser appdoes.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//Activities and WebViews measure progress with different scales.
//The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://developer.android.com/");
<?xml version="1.0" encoding="utf-8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
<manifest ... > <uses-permission android:name="android.permission.INTERNET" /> </manifest>
WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true);
public class WebAppInterface {
Context mContext;
/** Instantiatethe interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toastfrom the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
WebView webView = (WebView) findViewById(R.id.webview); webView.addJavascriptInterface(new WebAppInterface(this), "Android");
<input type="button" value="Sayhello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new WebViewClient());
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override;let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch anotherActivity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new MyWebViewClient());
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if thekey event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn'tthe Back key or there's no web page history, bubble up to the default
// systembehavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有