android 标题栏进度圈使用方法,Android 自定义标题栏 显示网页加载进度的方法实例...
這陣子在做Lephone的適配,測試組提交一個(gè)bug:標(biāo)題欄的文字較長時(shí)沒有顯示完全,其實(shí)這并不能算個(gè)bug,并且這個(gè)問題在以前其他機(jī)器也沒有出現(xiàn),只是說在Lephone的這個(gè)平臺上顯示得不怎么美觀,因?yàn)槁?lián)想將原生的標(biāo)題欄UI進(jìn)行了修改。修改的過程中遇到了一個(gè)難題,系統(tǒng)自帶的那個(gè)標(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修改后的都帶有一個(gè)返回按鈕,并且標(biāo)題文本和進(jìn)度條是Frame布局的不怎么好看)。
1、首先定義一個(gè)RelativeLayout布局文件 broser_custom_title.xml (AlwaysMarqueeTextView這個(gè)類重寫了TextView,實(shí)現(xiàn)一個(gè)跑馬燈的效果,網(wǎng)上能夠找到
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
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:layout_centerVertical="true"/>
android:layout_width="fill_parent" android:layout_height="2sp"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone" android:layout_alignParentBottom="true"
>
2、繼承WebChromeClient,重寫onProgressChanged和onReceivedTitle事件(進(jìn)度條加載完成后使用動畫漸退)
public class MyWebChromeClient extends WebChromeClient {
private Activity activity;
private ProgressBar pb;
private TextView tvtitle;
public MyWebChromeClient(Activity activity) {
this.activity = activity;
}
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);
// 運(yùn)行動畫 animation
pb.startAnimation(animation);
// 將 spinner 的可見性設(shè)置為不可見狀態(tài)
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、進(jìn)度條的動畫樣式 res/anim/animation.xml
4、碼設(shè)置自定義的標(biāo)題欄
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("https://www.jb51.net");
}
總結(jié)
以上是生活随笔為你收集整理的android 标题栏进度圈使用方法,Android 自定义标题栏 显示网页加载进度的方法实例...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win8能开发android的sdk么,
- 下一篇: java android 数组_Andr