package com.weidongjian.weigan.webviewdemo;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
/**
* Created by Weigan on 2014/11/29.
*/
public class MyWebView extends WebView {
private ProgressBar progressbar;
private Context mContext;
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
// progressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
progressbar = (ProgressBar) LayoutInflater.from(context).inflate(R.layout.progressbar, null);
progressbar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 6, 0, 0));
addView(progressbar);
// setWebViewClient(new WebViewClient(){});
setWebChromeClient(new WebChromeClient());
setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(mContext, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
this.getSettings().setBuiltInZoomControls(true);
this.getSettings().setUseWideViewPort(true);
}
public class WebChromeClient extends android.webkit.WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
progressbar.setVisibility(GONE);
} else {
if (progressbar.getVisibility() == GONE)
progressbar.setVisibility(VISIBLE);
progressbar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
LayoutParams lp = (LayoutParams) progressbar.getLayoutParams();
lp.x = l;
lp.y = t;
progressbar.setLayoutParams(lp);
super.onScrollChanged(l, t, oldl, oldt);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
仿照微信6的内置WebView控件
共92个文件
xml:34个
class:15个
png:8个
4星 · 超过85%的资源 需积分: 10 426 下载量 155 浏览量
2014-11-30
10:21:14
上传
评论 2
收藏 408KB ZIP 举报
温馨提示
1、在加载网页的时候,顶部有一个进度条,显示当前加载进度; 2、设置了所有的页面都在该控件中显示,不调用其他的浏览器; 3、支持手势放大缩小; 4、支持双击屏幕放大缩小; 5、按后退按钮,回到上一个网页;
资源推荐
资源详情
资源评论
收起资源包目录
WebViewDemo.zip (92个子文件)
WebViewDemo
gradlew.bat 2KB
gradlew 5KB
gradle.properties 870B
WebViewDemo.iml 870B
.gradle
1.12
taskArtifacts
fileHashes.bin 22KB
cache.properties.lock 17B
taskArtifacts.bin 43KB
fileSnapshots.bin 82KB
cache.properties 31B
outputFileStates.bin 19KB
app
proguard-rules.pro 662B
src
androidTest
java
com
weidongjian
weigan
webviewdemo
ApplicationTest.java 377B
main
res
menu
my.xml 336B
drawable-hdpi
ic_launcher.png 9KB
drawable-xhdpi
ic_launcher.png 14KB
drawable
greenprogress.xml 1KB
drawable-xxhdpi
ic_launcher.png 19KB
values
strings.xml 229B
styles.xml 205B
dimens.xml 216B
drawable-mdpi
ic_launcher.png 5KB
layout
activity_my.xml 556B
progressbar.xml 432B
fragment_my.xml 683B
values-v21
styles.xml 148B
values-w820dp
dimens.xml 364B
java
com
weidongjian
weigan
webviewdemo
MyWebView.java 2KB
MyActivity.java 2KB
AndroidManifest.xml 790B
app.iml 6KB
.gitignore 8B
build
outputs
apk
app-debug-unaligned.apk 58KB
app-debug.apk 58KB
intermediates
dex
debug
classes.dex 8KB
res
test
debug
debug
menu
my.xml 415B
drawable-mdpi-v4
ic_launcher.png 5KB
drawable-xxhdpi-v4
ic_launcher.png 18KB
values-w820dp-v13
values.xml 250B
drawable-xhdpi-v4
ic_launcher.png 14KB
drawable
greenprogress.xml 1KB
values
values.xml 823B
drawable-hdpi-v4
ic_launcher.png 9KB
layout
activity_my.xml 646B
progressbar.xml 522B
fragment_my.xml 773B
values-v21
values.xml 263B
manifests
test
debug
AndroidManifest.xml 693B
debug
AndroidManifest.xml 977B
ndk
debug
obj
lib
assets
test
debug
debug
symbols
test
debug
debug
dependency-cache
debug
classes
debug
com
weidongjian
weigan
webviewdemo
BuildConfig.class 757B
R$layout.class 519B
R$id.class 540B
R$drawable.class 492B
MyWebView$WebChromeClient.class 1KB
R$dimen.class 509B
R$attr.class 388B
R$menu.class 434B
R.class 837B
MyWebView.class 2KB
MyWebView$1.class 1KB
MyActivity$PlaceholderFragment.class 967B
MyActivity.class 2KB
R$string.class 520B
R$style.class 443B
incremental
aidl
test
debug
dependency.store 5B
debug
dependency.store 5B
mergeResources
test
debug
merger.xml 401B
debug
merger.xml 4KB
mergeAssets
test
debug
merger.xml 207B
debug
merger.xml 325B
pre-dexed
debug
rs
test
debug
obj
lib
debug
obj
lib
libs
app-debug-test.ap_ 778B
app-debug.ap_ 52KB
generated
res
generated
test
rs
test
debug
debug
source
buildConfig
test
debug
com
weidongjian
weigan
webviewdemo
test
BuildConfig.java 483B
debug
com
weidongjian
weigan
webviewdemo
BuildConfig.java 473B
aidl
test
debug
debug
r
test
debug
debug
com
weidongjian
weigan
webviewdemo
R.java 2KB
rs
test
debug
debug
build.gradle 568B
libs
gradle
wrapper
gradle-wrapper.jar 49KB
gradle-wrapper.properties 230B
.idea
scopes
scope_settings.xml 143B
gradle.xml 636B
misc.xml 860B
vcs.xml 173B
.name 11B
copyright
profiles_settings.xml 76B
modules.xml 371B
encodings.xml 171B
compiler.xml 734B
workspace.xml 91KB
.gitignore 87B
local.properties 428B
settings.gradle 16B
build
intermediates
model_data.bin 43KB
build.gradle 456B
共 92 条
- 1
WeiDongjian
- 粉丝: 56
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页