栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android 自定义加载动画Dialog弹窗效果的示例代码

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android 自定义加载动画Dialog弹窗效果的示例代码

效果图




首先是创建弹窗的背景

这是上面用到的
shape_bg_5_blue.xml为例,其他的三个无非就是里面的颜色不一样而已



 
 

然后是图片






因为有一个是白色的所以你看不见,但是依然可以保存到你本地文件夹下。

然后就是创建一个弹窗的样式


 
 @null
 true
 @drawable/shape_bg_5_yellow
 true
 @null
 

通过这个android:windowBackground的值改变不同的弹窗背景。
然后就是一个动画文件

这个文件一定要放在anim文件夹下(PS:什么?你说你没有这个文件夹?没有你就创建一个啊,我的天!)
loading_animation.xml代码如下:



 

下面就要创建一个现实内容的布局

布局代码如下:




 

 

接下来就是自定义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);//点击其他区域时 true 关闭弹窗 false 不关闭弹窗
 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
 }

	//关闭弹窗
 @Override
 public void dismiss() {
 super.dismiss();
 }

使用

这应该能看懂吧,写完收工。

总结

到此这篇关于Android 自定义加载动画Dialog弹窗效果的示例代码的文章就介绍到这了,更多相关Android 自定义加载 Dialog弹窗内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/154063.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号