Android 自定義加載動畫Dialog彈窗效果的示例代碼
效果圖





首先是創(chuàng)建彈窗的背景

這是上面用到的
以shape_bg_5_blue.xml為例,其他的三個無非就是里面的顏色不一樣而已
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="5dp"/> <solid android:color="#1C285B"/> </shape>
然后是圖片






因為有一個是白色的所以你看不見,但是依然可以保存到你本地文件夾下。
然后就是創(chuàng)建一個彈窗的樣式

<!-- 自定義loading dialog --> <style name="loading_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@drawable/shape_bg_5_yellow</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style>
通過這個android:windowBackground的值改變不同的彈窗背景。
然后就是一個動畫文件

這個文件一定要放在anim文件夾下(PS:什么?你說你沒有這個文件夾?沒有你就創(chuàng)建一個啊,我的天!)
loading_animation.xml代碼如下:
<?xml version="1.0" encoding="utf-8"?> <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="+360" android:duration="1500" android:startOffset="-1" android:repeatMode="restart" android:repeatCount="-1"/> </set>
下面就要創(chuàng)建一個現(xiàn)實內(nèi)容的布局

布局代碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_view" android:orientation="vertical" android:layout_width="120dp" android:layout_height="120dp" android:gravity="center" android:padding="10dp"> <ImageView android:id="@+id/iv_loading" android:layout_width="40dp" android:layout_height="40dp" android:src="@mipmap/icon_loading_5" /> <TextView android:id="@+id/tv_loading_tx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:maxLines="1" android:text="玩命加載中..." android:textColor="#FFF" android:textSize="14sp" /> </LinearLayout>
接下來就是自定義Dialog
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
/**
* 自定義彈窗
*/
public class CustomDialog extends Dialog {
TextView tvLoadingTx;
ImageView ivLoading;
public CustomDialog(Context context) {
this(context, R.style.loading_dialog, "玩命加載中...");
}
public CustomDialog(Context context, String string) {
this(context, R.style.loading_dialog, string);
}
protected CustomDialog(Context context, int theme, String string) {
super(context, theme);
setCanceledOnTouchOutside(true);//點擊其他區(qū)域時 true 關(guān)閉彈窗 false 不關(guān)閉彈窗
setContentView(R.layout.loading_dialog);//加載布局
tvLoadingTx = findViewById(R.id.tv_loading_tx);
tvLoadingTx.setText(string);
ivLoading = findViewById(R.id.iv_loading);
// 加載動畫
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
context, R.anim.loading_animation);
// 使用ImageView顯示動畫
ivLoading.startAnimation(hyperspaceJumpAnimation);
getWindow().getAttributes().gravity = Gravity.CENTER;//居中顯示
getWindow().getAttributes().dimAmount = 0.5f;//背景透明度 取值范圍 0 ~ 1
}
//關(guān)閉彈窗
@Override
public void dismiss() {
super.dismiss();
}
使用

這應(yīng)該能看懂吧,寫完收工。
總結(jié)
到此這篇關(guān)于Android 自定義加載動畫Dialog彈窗效果的示例代碼的文章就介紹到這了,更多相關(guān)Android 自定義加載 Dialog彈窗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android自定義Dialog的2種常見方法
- Android自定義Dialog框樣式
- Android自定義Dialog原理實例解析
- Android自定義底部彈出框ButtomDialog
- android自定義Dialog彈框和背景陰影顯示效果
- Android自定義Dialog實現(xiàn)通用圓角對話框
- Android自定義dialog 自下往上彈出的實例代碼
- Android 自定義Dialog去除title導(dǎo)航欄的解決方法
- Android自定義Dialog實現(xiàn)加載對話框效果
- Android編程自定義AlertDialog樣式的方法詳解
- 解決Android中自定義DialogFragment解決寬度和高度問題
- Android 自定義 Dialog 實現(xiàn)列表 單選,多選,搜索功能
相關(guān)文章
Kotlin?協(xié)程異步熱數(shù)據(jù)流的設(shè)計與使用講解
這篇文章主要為大家介紹了Kotlin?協(xié)程協(xié)程異步熱數(shù)據(jù)流的設(shè)計與使用講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Android開發(fā)之瀑布流控件的實現(xiàn)與使用方法示例
這篇文章主要介紹了Android開發(fā)之瀑布流控件的實現(xiàn)與使用方法,結(jié)合實例形式分析了Android瀑布流控件的定義與使用方法,需要的朋友可以參考下2017-10-10
Android13?加強(qiáng)Intent?filters?的安全性
這篇文章主要介紹了Android13?加強(qiáng)Intent?filters?的安全性,文章基于Android13?展開Intent?filters?安全性加強(qiáng)的詳細(xì)介紹,需要的小伙伴可以參考一下2022-05-05
android隱式意圖激活自定義界面和系統(tǒng)應(yīng)用界面的實例
下面小編就為大家?guī)硪黄猘ndroid隱式意圖激活自定義界面和系統(tǒng)應(yīng)用界面的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06
Android使用Fragment實現(xiàn)兼容手機(jī)和平板的程序
這篇文章主要介紹了Android使用Fragment實現(xiàn)兼容手機(jī)和平板的程序,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-04-04
Android中Fragment多層嵌套時onActivityResult無法正確回調(diào)問題的解決方法
這篇文章主要介紹了Android中Fragment多層嵌套時onActivityResult無法正確回調(diào)問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09

