Android仿微信網(wǎng)絡(luò)加載彈出框
本文實(shí)例為大家分享了Android仿微信網(wǎng)絡(luò)加載彈出框的具體代碼,供大家參考,具體內(nèi)容如下
沒有餓了么的動(dòng)畫效果好看,但是,特別適用,拿來(lái)就用!
看一下效果圖

圖片素材

好了,其實(shí)很簡(jiǎn)單,就是一個(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><!--無(wú)標(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.加載對(duì)話框的背景
<!-- 加載對(duì)話框布局 -->
<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í)頁(yè)面不可點(diǎn)擊,只能點(diǎn)擊返回 customDialog.dismiss();//消失
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義底部彈出框ButtomDialog
- Android自定義view仿iOS彈出框效果
- Android使用popUpWindow帶遮罩層的彈出框
- Android實(shí)現(xiàn)底部半透明彈出框PopUpWindow效果
- Android自定義彈出框dialog效果
- Android實(shí)現(xiàn)蒙版彈出框效果
- Android 多種簡(jiǎn)單的彈出框樣式設(shè)置代碼
- Android實(shí)現(xiàn)可輸入數(shù)據(jù)的彈出框
- Android使用Dialog風(fēng)格彈出框的Activity
- android自定義彈出框樣式的實(shí)現(xiàn)方法
相關(guān)文章
android避免彈出軟鍵盤遮蓋listview的簡(jiǎn)單方法
下面小編就為大家?guī)?lái)一篇android避免彈出軟鍵盤遮蓋listview的簡(jiǎn)單方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09
Android使用Intent傳大數(shù)據(jù)簡(jiǎn)單實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Android使用Intent傳大數(shù)據(jù)簡(jiǎn)單實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Android中手機(jī)震動(dòng)的設(shè)置(Vibrator)的步驟簡(jiǎn)要說(shuō)明
Android中手機(jī)震動(dòng)的設(shè)置(Vibrator)的步驟,很詳細(xì),感興趣的朋友可以了解下哦2013-01-01
Android?studio實(shí)現(xiàn)單選按鈕
這篇文章主要為大家詳細(xì)介紹了Android?studio實(shí)現(xiàn)單選按鈕,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
android中webview控件和javascript交互實(shí)例
這篇文章主要介紹了android中webview控件和javascript交互實(shí)例,例子中包括javascript調(diào)用java的方法,java代碼中調(diào)用javascript的方法,需要的朋友可以參考下2014-07-07
android打開應(yīng)用所在的市場(chǎng)頁(yè)面進(jìn)行評(píng)分操作的方法
這篇文章主要介紹了android打開應(yīng)用所在的市場(chǎng)頁(yè)面進(jìn)行評(píng)分操作的方法,涉及Android操作市場(chǎng)頁(yè)面評(píng)分效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
Android開發(fā)之利用jsoup解析HTML頁(yè)面的方法
這篇文章主要介紹了Android開發(fā)之利用jsoup解析HTML頁(yè)面的方法,結(jié)合實(shí)例形式分析了Android基于jsoup jar包來(lái)抓取html頁(yè)面的實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-03-03
Android實(shí)例HandlerThread源碼分析
本篇文章主要給大家通過(guò)實(shí)例代碼分析了Android中HandlerThread的用法以及步驟,需要的朋友參考學(xué)習(xí)下吧。2017-12-12
Android binder 匿名服務(wù)實(shí)現(xiàn)雙向通信的解決方案
這篇文章主要介紹了Android binder 匿名服務(wù)實(shí)現(xiàn)雙向通信的解決方案,當(dāng)然,這種方案是可行的,只是需要client和server都向servicemanager注冊(cè)一個(gè)服務(wù),實(shí)現(xiàn)起來(lái)有點(diǎn)麻煩,不太建議這么做,需要的朋友可以參考下2024-04-04
Android框架Volley之利用Imageloader和NetWorkImageView加載圖片的方法
這篇文章主要介紹了Android框架Volley之利用Imageloader和NetWorkImageView加載圖片的實(shí)現(xiàn)方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-05-05

