Android 加载网页进度条


  1、首先定义一个RelativeLayout布局文件 broser_custom_title.xml (AlwaysMarqueeTextView这个类重写了TextView,实现一个跑马灯的效果,网上能够找到)
Java代码:
XML/HTML代码
  1. < ?xml version="1.0" encoding="utf-8"?>
  2. < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
  3. android:layout_height="fill_parent">
  4. < com.android.CustomTitleTest
  5. android:id="@+id/tvtitle"
  6. android:layout_width="fill_parent"
  7. android:layout_height="wrap_content"
  8. android:focusableInTouchMode="true"
  9. android:singleLine="true"
  10. android:ellipsize="marquee"
  11. android:focusable="false"
  12. android:marqueeRepeatLimit="marquee_forever"
  13. android:textSize="20sp" android:layout_centerVertical="true"/>
  14. < ProgressBar
  15. android:id="@+id/pb"
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. style="?android:attr/progressBarStyleHorizontal"
  19. android:visibility="gone"
  20. android:layout_alignParentBottom="true" >
  21. < /ProgressBar>

  22. < /RelativeLayout>

2、继承WebChromeClient,重写onProgressChanged和onReceivedTitle事件(进度条加载完成后使用动画渐退)
java代码:
  1. public class MyWebChromeClient extends WebChromeClient {
  2. private Activity activity;
  3. private ProgressBar pb;
  4. private TextView tvtitle;
  5. public MyWebChromeClient(Activity activity) {
  6. this.activity = activity;
  7. }



Java代码:
  1. Animation animation;

  2. @Override
  3. public void onProgressChanged(WebView view, int newProgress) {
  4. pb=(ProgressBar)activity.findViewById(R.id.pb);
  5. pb.setMax(100);
  6. if(newProgress<100){
  7. if(pb.getVisibility()==View.GONE) pb.setVisibility(View.VISIBLE);
  8. pb.setProgress(newProgress);
  9. }else{
  10. pb.setProgress(100);
  11. animation=AnimationUtils.loadAnimation(activity, R.anim.animation);
  12. // 运行动画
  13. animation pb.startAnimation(animation);
  14. // 将 spinner 的可见性设置为不可见状态
  15. pb.setVisibility(View.INVISIBLE);
  16. }
  17. super.onProgressChanged(view, newProgress);
  18. }
  19. @Override
  20. public void onReceivedTitle(WebView view, String title) {
  21. tvtitle=(TextView)activity.findViewById(R.id.tvtitle);
  22. tvtitle.setText(title); super.onReceivedTitle(view, title);

  23. }

  24. }

3、进度条的动画样式 res/anim/animation.xml
java代码:
XML/HTML代码
  1. < ?xml version="1.0" encoding="utf-8"?> < set xmlns:android="http://schemas.android.com/apk/res/android">
  2. < alpha android:fromAlpha="1.0"
  3. android:toAlpha="0.0"
  4. android:duration="700"/>
  5. < /set>

4、码设置自定义的标题栏
java代码:
  1. private WebView browser;
  2. @Override
  3. public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);
  4. getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
  5. setContentView(R.layout.main);
  6. getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.broser_custom_title); browser = (WebView) findViewById(R.id.my_browser);
  7. // currentWebView=browser;
  8. browser.setWebChromeClient(new MyWebChromeClient(Main.this));
  9. browser.loadUrl(“http://www.eoeandroid.com”); }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值