Android 自定義加載動(dòng)畫Dialog彈窗效果的示例代碼
效果圖





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

這是上面用到的
以shape_bg_5_blue.xml為例,其他的三個(gè)無非就是里面的顏色不一樣而已
<?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>
然后是圖片






因?yàn)橛幸粋€(gè)是白色的所以你看不見,但是依然可以保存到你本地文件夾下。
然后就是創(chuàng)建一個(gè)彈窗的樣式

<!-- 自定義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>
通過這個(gè)android:windowBackground的值改變不同的彈窗背景。
然后就是一個(gè)動(dòng)畫文件

這個(gè)文件一定要放在anim文件夾下(PS:什么?你說你沒有這個(gè)文件夾?沒有你就創(chuàng)建一個(gè)啊,我的天!)
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>
下面就要?jiǎng)?chuàng)建一個(gè)現(xiàn)實(shí)內(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);//點(diǎn)擊其他區(qū)域時(shí) 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);
// 加載動(dòng)畫
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
context, R.anim.loading_animation);
// 使用ImageView顯示動(dòng)畫
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 自定義加載動(dòng)畫Dialog彈窗效果的示例代碼的文章就介紹到這了,更多相關(guān)Android 自定義加載 Dialog彈窗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android自定義Dialog的2種常見方法
- Android自定義Dialog框樣式
- Android自定義Dialog原理實(shí)例解析
- Android自定義底部彈出框ButtomDialog
- android自定義Dialog彈框和背景陰影顯示效果
- Android自定義Dialog實(shí)現(xiàn)通用圓角對話框
- Android自定義dialog 自下往上彈出的實(shí)例代碼
- Android 自定義Dialog去除title導(dǎo)航欄的解決方法
- Android自定義Dialog實(shí)現(xiàn)加載對話框效果
- Android編程自定義AlertDialog樣式的方法詳解
- 解決Android中自定義DialogFragment解決寬度和高度問題
- Android?自定義?Dialog?實(shí)現(xiàn)列表?單選、多選、搜索功能
相關(guān)文章
OpenGL ES 矩陣變換及其數(shù)學(xué)原理詳解(五)
這篇文章主要為大家詳細(xì)介紹了OpenGL ES 矩陣變換及其數(shù)學(xué)原理的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android的webview支持HTML5的離線應(yīng)用功能詳細(xì)配置
HTML5的離線應(yīng)用功能可以使得WebApp即使在網(wǎng)絡(luò)斷開的情況下仍能正常使用這是個(gè)非常有用的功能,但如何使Webivew支持HTML5離線應(yīng)用功能呢,需要的朋友可以參考下2012-12-12
Android實(shí)現(xiàn)excel/pdf/word/odt/圖片相互轉(zhuǎn)換
這篇文章主要為大家詳細(xì)介紹了Android如何實(shí)現(xiàn)excel/pdf/word/odt/圖片之間的相互轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-04-04
如何使用Flutter實(shí)現(xiàn)58同城中的加載動(dòng)畫詳解
這篇文章主要給大家介紹了關(guān)于如何使用Flutter實(shí)現(xiàn)58同城中加載動(dòng)畫詳?shù)南嚓P(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
android開發(fā)仿ios的UIScrollView實(shí)例代碼
下面小編就為大家分享一篇android開發(fā)仿ios的UIScrollView實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
anroid開發(fā)教程之spinner下拉列表的使用示例
這篇文章主要介紹了anroid的spinner下拉列表的使用示例,需要的朋友可以參考下2014-04-04

