android进度条
1、达到的效果
2、布局代码
先写一个my_browser.xml文件 存放WebView<?xml version=”1.0″ encoding=”utf-8″?>
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
android:id=”@+id/webView”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” />
进度条布局
然后写一个broser.xml存放进度条的
xml version=”1.0″ encoding=”utf-8″?>
android:layout_height=”fill_parent”>
android:id=”@+id/tvtitle”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:focusableInTouchMode=”true”
android:singleLine=”true”
android:ellipsize=”marquee”
android:focusable=”false”
android:marqueeRepeatLimit=”marquee_forever”
android:textSize=”20sp” android:layout_centerVertical=”true”/>
android:id=”@+id/pb”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
style=”?android:attr/progressBarStyleHorizontal”
android:visibility=”gone”
android:layout_alignParentBottom=”true” >
WebChromeClient
重写onProgressChanged和onReceivedTitle事件(进度条载入完毕后使用动画渐退)/**
* MyWebChromeClient.java
* 版权全部(C) 2012* 创建:cuiran 2012-10-16 下午3:05:34
*/
package com.cayden.citygirl.activity;
import android.app.Activity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
* TODO
* @author cuiran
* @version TODO
*/
public class MyWebChromeClient extends WebChromeClient {
private Activity activity;
private ProgressBar pb;
private Animation animation;
private TextView tvtitle;
public MyWebChromeClient(Activity activity) {
this.activity = activity;
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
pb=(ProgressBar)activity.findViewById(R.id.pb);
pb.setMax(100);
if(newProgress<100){
if(pb.getVisibility()==View.GONE) pb.setVisibility(View.VISIBLE);
pb.setProgress(newProgress);
}else{
pb.setProgress(100);
animation=AnimationUtils.loadAnimation(activity, R.anim.animation);
// 执行动画
pb.startAnimation(animation);
// 将 spinner 的可见性设置为不可见状态
pb.setVisibility(View.INVISIBLE);
}
super.onProgressChanged(view, newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
tvtitle=(TextView)activity.findViewById(R.id.tvtitle);
tvtitle.setText(title);
super.onReceivedTitle(view, title);
}
}
进度条的动画样式 res/anim/animation.xml
xml version=”1.0″ encoding=”utf-8″?>
android:toAlpha=”0.0″
android:duration=”700″/>
5、程序启动类/**
* ProgressActivity.java
* 版权全部(C) 2012
* 创建:cuiran 2012-10-16 下午3:13:49
*/
package com.cayden.citygirl.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;
/**
* TODO
* @author cuiran
* @version TODO
*/
public class ProgressActivity extends Activity {
private WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_browser);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.broser);
browser = (WebView) findViewById(R.id.webView);
// currentWebView=browser;
browser.setWebChromeClient(new MyWebChromeClient(ProgressActivity.this));
browser.loadUrl(“http://shop.paipai.com/731681975/”);
}
}
今天的文章android进度对话框_Android11data分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/72648.html