偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Android自定義標(biāo)題欄:顯示網(wǎng)頁加載進(jìn)度

移動開發(fā) Android
本文的作者是一位Android開發(fā)者,在做聯(lián)想Lephone的適配的過程中,遇到了一個難題,系統(tǒng)自帶標(biāo)題欄進(jìn)度不能顯示100%。通過這個實(shí)例,作者在本文中介紹了在Android開發(fā)中如何用進(jìn)度條顯示網(wǎng)頁的加載進(jìn)度。

這陣子在做Lephone的適配,測試組提交一個bug:標(biāo)題欄的文字較長時沒有顯示完全,其實(shí)這并不能算個bug,并且這個問題在以前其他機(jī)器也沒有出現(xiàn),只是說在Lephone的這個平臺上顯示得不怎么美觀,因?yàn)槁?lián)想將原生的標(biāo)題欄UI進(jìn)行了修改。修改的過程中遇到了一個難題,系統(tǒng)自帶的那個標(biāo)題欄進(jìn)度總能夠到達(dá)100%后漸退,但是我每次***到100%那一段顯示不全,嘗試了用線程程序死了卡主了不說,還是一樣的效果,后來同事一句話提醒了我用動畫。確實(shí)是這樣我猜系統(tǒng)的也是這樣實(shí)現(xiàn)的,等進(jìn)度到達(dá)100%后,用動畫改變它的透明度就ok了。

實(shí)現(xiàn)的效果:標(biāo)題欄顯示網(wǎng)頁標(biāo)題并且滾動,并且用進(jìn)度條顯示網(wǎng)頁的加載進(jìn)度(重新自定義標(biāo)題欄,lephone修改后的都帶有一個返回按鈕,并且標(biāo)題文本和進(jìn)度條是Frame布局的不怎么好看)。

1、首先定義一個RelativeLayout布局文件 broser_custom_title.xml (AlwaysMarqueeTextView這個類重寫了TextView,實(shí)現(xiàn)一個跑馬燈的效果,網(wǎng)上能夠找到)

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android" 
  4.   android:layout_width="fill_parent" 
  5.   android:layout_height="fill_parent">  
  6.       <com.android.CustomTitleTest  
  7.             android:id="@+id/tvtitle" 
  8.             android:layout_width="fill_parent" 
  9.             android:layout_height="wrap_content" 
  10.  android:focusableInTouchMode="true" 
  11.             android:singleLine="true" 
  12.  android:ellipsize="marquee" 
  13.             android:focusable="false" 
  14.  android:marqueeRepeatLimit="marquee_forever" 
  15.             android:textSize="20sp" 
  16.  android:layout_centerVertical="true"/>  
  17.     <ProgressBar android:id="@+id/pb" 
  18.          android:layout_width="fill_parent" 
  19.  android:layout_height="wrap_content" 
  20.         style="?android:attr/progressBarStyleHorizontal" 
  21.         android:visibility="gone" 
  22.  android:layout_alignParentBottom="true" 
  23.  
  24.                 ></ProgressBar>  
  25. </RelativeLayout> 

2、繼承WebChromeClient,重寫onProgressChanged和onReceivedTitle事件(進(jìn)度條加載完成后使用動畫漸退)

 

  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.     }  
  8.     Animation animation;  
  9.       @Override 
  10.     public void onProgressChanged(WebView view, int newProgress) {  
  11.         pb=(ProgressBar)activity.findViewById(R.id.pb);  
  12.         pb.setMax(100);  
  13.         if(newProgress<100){  
  14.             if(pb.getVisibility()==View.GONE)  
  15.                 pb.setVisibility(View.VISIBLE);  
  16.             pb.setProgress(newProgress);  
  17.         }else{  
  18.             pb.setProgress(100);  
  19.             animation=AnimationUtils.loadAnimation(activity, R.anim.animation);  
  20.             // 運(yùn)行動畫 animation  
  21.               pb.startAnimation(animation);  
  22.               // 將 spinner 的可見性設(shè)置為不可見狀態(tài)  
  23.               pb.setVisibility(View.INVISIBLE);  
  24.          }  
  25.                 super.onProgressChanged(view, newProgress);  
  26.     }  
  27.     @Override 
  28.     public void onReceivedTitle(WebView view, String title) {  
  29.         tvtitle=(TextView)activity.findViewById(R.id.tvtitle);  
  30.         tvtitle.setText(title);  
  31.         super.onReceivedTitle(view, title);  
  32.     }  

3、進(jìn)度條的動畫樣式 res/anim/animation.xml

  1. <?xml version="1.0" encoding="utf-8"?> 
  2.     <set xmlns:android="http://schemas.android.com/apk/res/android"> 
  3.          <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="700"/> 
  4.    </set> 

4、碼設(shè)置自定義的標(biāo)題欄

  1. private WebView browser;  
  2. @Override 
  3. public void onCreate(Bundle savedInstanceState)  
  4.       super.onCreate(savedInstanceState);  
  5.     getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);  
  6.     setContentView(R.layout.main);  
  7.     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.broser_custom_title);  
  8.     browser = (WebView) findViewById(R.id.my_browser);  
  9.     // currentWebView=browser;  
  10.     browser.setWebChromeClient(new MyWebChromeClient(Main.this));  
  11.     browser.loadUrl("http://www.163.com");  

 

【編輯推薦】

  1. 深入理解Android消息處理系統(tǒng)原理
  2. Android用戶界面設(shè)計:框架布局
  3. Android游戲開發(fā):如何實(shí)現(xiàn)爆炸效果
  4. 盤點(diǎn)Android開發(fā)者必備的十大開發(fā)工具
  5. Android設(shè)計趨勢分析10則
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2011-02-22 14:53:41

titlebar標(biāo)題欄Android

2013-12-19 14:16:46

Android ApiAndroid開發(fā)Android SDK

2017-02-13 17:17:48

Android標(biāo)題欄控件

2017-05-03 16:30:38

AndroidScrollView滾動視圖

2013-07-18 16:09:10

自定義iOS狀態(tài)欄iOS開發(fā)iOS學(xué)習(xí)

2021-08-24 15:25:59

鴻蒙HarmonyOS應(yīng)用

2021-10-26 10:07:02

鴻蒙HarmonyOS應(yīng)用

2015-08-14 17:47:35

Windows 10標(biāo)題欄

2017-03-14 15:09:18

AndroidView圓形進(jìn)度條

2016-11-16 21:55:55

源碼分析自定義view androi

2016-12-26 15:25:59

Android自定義View

2009-11-03 18:05:00

VB.NET窗體標(biāo)題欄

2012-12-24 14:42:48

iOS自定義狀態(tài)欄

2021-09-06 14:58:23

鴻蒙HarmonyOS應(yīng)用

2013-12-19 14:28:04

Android ApiAndroid開發(fā)Android SDK

2013-04-01 14:35:10

Android開發(fā)Android自定義x

2023-06-26 07:21:41

標(biāo)題欄鼠標(biāo)標(biāo)題

2022-02-13 19:05:19

微軟Windows 11

2013-12-26 17:08:36

Android開發(fā)Android應(yīng)用自定義Adapter顯

2010-02-07 14:02:16

Android 界面
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號