Android仿微信網(wǎng)絡(luò)加載彈出框
本文實(shí)例為大家分享了Android仿微信網(wǎng)絡(luò)加載彈出框的具體代碼,供大家參考,具體內(nèi)容如下
沒有餓了么的動(dòng)畫效果好看,但是,特別適用,拿來就用!
看一下效果圖
圖片素材
好了,其實(shí)很簡單,就是一個(gè)自定義Dialog的控件而已
1. 自定義view的style樣式
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <!-- 自定義dialog的樣式 --> <style name="CustomDialog"> <item name="android:windowFrame">@null</item><!--邊框--> <item name="android:windowIsFloating">true</item><!--是否浮現(xiàn)在activity之上--> <item name="android:windowIsTranslucent">false</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--無標(biāo)題--> <item name="android:windowBackground">@drawable/dialog_custom_bg</item><!--背景透明--> <item name="android:backgroundDimEnabled">false</item><!--模糊--> <item name="android:backgroundDimAmount">0.6</item> </style> </resources>
2.dialog_custom_bg 加載動(dòng)畫shape背景圖(drawable文件夾下)
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ff333333" /> <corners android:radius="5dp" /> </shape>
3.indeterminate_drawable 進(jìn)度條模糊背景圖(drawable文件夾下)
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/loading" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360"> </rotate>
4.加載對話框的背景
<!-- 加載對話框布局 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" android:padding="10dp"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminateDrawable="@drawable/indeterminate_drawable" android:indeterminateDuration="1800" /> <TextView android:id="@+id/tvcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" android:text="加載中" android:textColor="#ffffff" android:textSize="14sp" /> </LinearLayout>
5.CustomDialog自定義控件
public class CustomDialog extends Dialog { private String content; public CustomDialog(Context context, String content) { super(context, R.style.CustomDialog); this.content=content; initView(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode){ case KeyEvent.KEYCODE_BACK: if(CustomDialog.this.isShowing()) CustomDialog.this.dismiss(); break; } return true; } private void initView(){ setContentView(R.layout.dialog_view); ((TextView)findViewById(R.id.tvcontent)).setText(content); setCanceledOnTouchOutside(true); WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.alpha=0.8f; getWindow().setAttributes(attributes); setCancelable(false); } }
6.Activity中直接調(diào)用
CustomDialog customDialog = new CustomDialog(this, "正在加載..."); customDialog.show();//顯示,顯示時(shí)頁面不可點(diǎn)擊,只能點(diǎn)擊返回 customDialog.dismiss();//消失
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)之ViewFlipper自動(dòng)播放圖片功能實(shí)現(xiàn)方法示例
這篇文章主要介紹了Android開發(fā)之ViewFlipper自動(dòng)播放圖片功能實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android使用ViewFlipper實(shí)現(xiàn)圖片播放的相關(guān)界面布局及功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-03-03Android關(guān)于BottomNavigationView使用指南
本文主要介紹了Android關(guān)于BottomNavigationView使用指南,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01android 關(guān)于webview 加載h5網(wǎng)頁開啟定位的方法
今天小編就為大家分享一篇android 關(guān)于webview 加載h5網(wǎng)頁開啟定位的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07Android巧用ActionBar實(shí)現(xiàn)下拉式導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了Android巧用ActionBar實(shí)現(xiàn)下拉式導(dǎo)航的相關(guān)資料,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05關(guān)于WebView 重定向行為導(dǎo)致的多次加載的問題
這篇文章主要介紹了關(guān)于WebView 重定向行為導(dǎo)致的多次加載的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Flutter實(shí)現(xiàn)編寫富文本Text的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何通過Flutter實(shí)現(xiàn)編寫富文本Text,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下2022-11-1125個(gè)實(shí)用酷炫的Android開源UI框架
本文為大家分享了25個(gè)實(shí)用酷炫的Android開源UI框架,靈活運(yùn)用這些UI框架可在日常工作中節(jié)省不少時(shí)間2018-04-04Android自定義動(dòng)態(tài)壁紙開發(fā)詳解
這篇文章主要為大家詳細(xì)介紹了Android自定義動(dòng)態(tài)壁紙開發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01