1、首先定义一个RelativeLayout布局文件 broser_custom_title.xml (AlwaysMarqueeTextView这个类重写了TextView,实现一个跑马灯的效果,网上能够找到)
Java代码:
XML/HTML代码
- < ?xml version="1.0" encoding="utf-8"?>
- < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- < com.android.CustomTitleTest
- 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"/>
- < ProgressBar
- 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" >
- < /ProgressBar>
- < /RelativeLayout>
2、继承WebChromeClient,重写onProgressChanged和onReceivedTitle事件(进度条加载完成后使用动画渐退)
java代码:
- public class MyWebChromeClient extends WebChromeClient {
- private Activity activity;
- private ProgressBar pb;
- private TextView tvtitle;
- public MyWebChromeClient(Activity activity) {
- this.activity = activity;
- }
Java代码:
- Animation animation;
- @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);
- // 运行动画
- 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);
- }
- }
3、进度条的动画样式 res/anim/animation.xml
java代码:
XML/HTML代码
XML/HTML代码
- < ?xml version="1.0" encoding="utf-8"?> < set xmlns:android="http://schemas.android.com/apk/res/android">
- < alpha android:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:duration="700"/>
- < /set>
4、码设置自定义的标题栏
java代码:
- private WebView browser;
- @Override
- public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);
- getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
- setContentView(R.layout.main);
- getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.broser_custom_title); browser = (WebView) findViewById(R.id.my_browser);
- // currentWebView=browser;
- browser.setWebChromeClient(new MyWebChromeClient(Main.this));
- browser.loadUrl(“http://www.eoeandroid.com”); }