android基于dialog實(shí)現(xiàn)等待加載框示例
最近想找一些新穎的等待框,但一直找不到理想的效果,沒有辦法,只好自己動(dòng)手豐衣足食了。
先給大家看個(gè)效果圖!
首先就是新建一個(gè)dialog的XML文件了
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ic_loading_bg" android:gravity="center" android:orientation="vertical" android:padding="16.0dip" > <ProgressBar android:layout_width="24.0dip" android:layout_height="24.0dip" android:indeterminateDrawable="@drawable/progress_drawable_white" /> <TextView android:id="@+id/id_tv_loadingmsg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginTop="8.0dip" android:textColor="@color/white" android:textSize="16.0dip" /> </LinearLayout>
ic_loading_bg就是一個(gè)背景的圖片。
關(guān)于上面的drawable中的progress_drawable_white.xml文件如下
<?xml version="1.0" encoding="utf-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="83" android:drawable="@drawable/ic_loading_white_01" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_02" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_03" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_04" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_05" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_06" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_07" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_08" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_09" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_10" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_11" /> <item android:duration="83" android:drawable="@drawable/ic_loading_white_12" /> </animation-list>
這12個(gè)都是圖片來的。
核心顯示等待框代碼如下
progressDialog = new Dialog(AboutActivity.this,R.style.progress_dialog); progressDialog.setContentView(R.layout.progress); progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg); msg.setText("賣力加載中"); progressDialog.show();
其中的文字可以自己改了,方便直接。
給新手的提示,記得在開頭寫上 private Dialog progressDialog;(老鳥可以忽略這個(gè)啦)
里面有個(gè)style,加上下面的代碼到style.xml文件里面就OK了!
<style name="progress_dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:background">@null</item> <item name="android:windowBackground">@null</item> <item name="android:backgroundDimEnabled">false</item> </style>
關(guān)于如何讓這個(gè)消失,在需要消失的地方加上
progressDialog.dismiss();
就OK了
demo下載地址:ProgressDialog_jb51.rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)之imageView圖片按比例縮放的實(shí)現(xiàn)方法
這篇文章主要介紹了Android開發(fā)之imageView圖片按比例縮放的實(shí)現(xiàn)方法,較為詳細(xì)的分析了Android中ImageView控件的scaleType屬性控制圖片縮放的具體用法,需要的朋友可以參考下2016-01-01解決Eclipse啟動(dòng)出錯(cuò):Failed to create the Java Virtual Machine
這篇文章主要介紹了解決Eclipse啟動(dòng)出錯(cuò):Failed to create the Java Virtual Machine的相關(guān)資料,這里說明出錯(cuò)原因及查找錯(cuò)誤和解決辦法,需要的朋友可以參考下2017-07-07android實(shí)現(xiàn)多圖文分享朋友圈功能
本文主要介紹android調(diào)用系統(tǒng)分享實(shí)現(xiàn)朋友圈同時(shí)分享文字和圖片,圖片還可以多圖添加分享的功能。2017-11-11Android懸浮窗按鈕實(shí)現(xiàn)點(diǎn)擊并顯示/隱藏多功能列表
這篇文章主要為大家詳細(xì)介紹了Android懸浮窗按鈕實(shí)現(xiàn)點(diǎn)擊并顯示/隱藏多功能列表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07Android ListView分頁(yè)功能實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Android ListView分頁(yè)功能的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05monkeyrunner之電腦安裝驅(qū)動(dòng)(5)
這篇文章主要為大家詳細(xì)介紹了monkeyrunner之電腦安裝驅(qū)動(dòng)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android中ShapeableImageView使用實(shí)例詳解(告別shape、三方庫(kù))
之前Google推送了文章,Android?Material組件1.2.0里面就有ShapeableImageView,不用像以前再寫shape,下面這篇文章主要給大家介紹了關(guān)于Android中ShapeableImageView使用的相關(guān)資料,需要的朋友可以參考下2022-09-09Android實(shí)現(xiàn)代碼畫虛線邊框背景效果
可能之前遇到這樣的需求大家都會(huì)想到用圖片背景來解決,下面這篇文章將給大家介紹Android如何利用代碼畫虛線邊框背景的效果,有需要的朋友們可以參考借鑒,下面來跟著小編一起學(xué)習(xí)學(xué)習(xí)吧。2016-12-12