服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android仿微信网络加载弹出框

Android仿微信网络加载弹出框

2022-10-21 14:40AND_Devil Android

这篇文章主要为大家详细介绍了Android仿微信网络加载弹出框,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Android仿微信网络加载弹出框的具体代码,供大家参考,具体内容如下

没有饿了么的动画效果好看,但是,特别适用,拿来就用!

看一下效果图

Android仿微信网络加载弹出框

图片素材

Android仿微信网络加载弹出框

好了,其实很简单,就是一个自定义Dialog的控件而已

1. 自定义view的style样式

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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><!--是否浮现在activity之上-->
    <item name="android:windowIsTranslucent">false</item><!--半透明-->
    <item name="android:windowNoTitle">true</item><!--无标题-->
    <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 加载动画shape背景图(drawable文件夹下)

?
1
2
3
4
5
<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 进度条模糊背景图(drawable文件夹下)

?
1
2
3
4
5
6
7
8
<?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.加载对话框的背景

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!-- 加载对话框布局 -->
<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自定义控件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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中直接调用

?
1
2
3
CustomDialog customDialog = new CustomDialog(this, "正在加载...");
customDialog.show();//显示,显示时页面不可点击,只能点击返回
customDialog.dismiss();//消失

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_40543575/article/details/79570076

延伸 · 阅读

精彩推荐
  • AndroidKotlin中的高阶函数深入讲解

    Kotlin中的高阶函数深入讲解

    这篇文章主要给大家介绍了关于Kotlin中高阶函数的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的...

    ScottSong3532022-08-16
  • AndroidAndroid利用BitMap获得图片像素数据的方法

    Android利用BitMap获得图片像素数据的方法

    这篇文章主要介绍了Android利用BitMap获得图片像素数据的方法,结合实例对比分析了Android获取图片像素数据的相关技巧,需要的朋友可以参考下...

    fengyee_zju7272021-05-24
  • AndroidAndroid仿京东首页秒杀倒计时

    Android仿京东首页秒杀倒计时

    这篇文章主要为大家详细介绍了Android仿京东首页秒杀倒计时,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    拉莫帅9522022-09-19
  • Android深入android Unable to resolve target 'android-XX'详解

    深入android Unable to resolve target 'android-XX'详解

    本篇文章是对android Unable to resolve target 'android-XX'错误的解决方法进行了详细的分析介绍,需要的朋友参考下...

    Android开发网4412021-01-28
  • AndroidAndroid编程之控件状态配置文件实例

    Android编程之控件状态配置文件实例

    这篇文章主要介绍了Android编程之控件状态配置文件,以实例形式分析了Android控件状态配置文件对于选中、获得焦点、按下时的状态等相关设置技巧,需要的朋...

    chenguang797672021-05-10
  • AndroidAndroid之线程池ThreadPoolExecutor的简介

    Android之线程池ThreadPoolExecutor的简介

    今天小编就为大家分享一篇关于Android之线程池ThreadPoolExecutor的简介,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随...

    smile05286202022-09-29
  • AndroidAndroid 初识 Helloworld 详解

    Android 初识 Helloworld 详解

    在Eclipse+ADT中创建HelloWorld非常简单,直接按照导航下一步就可以了。本文重点不在如何创建,而在理解HelloWorld项目的文件。需要的朋友可以参考下...

    Android开发网5232021-02-03
  • AndroidAndroid Studio中的Gradle依赖深入讲解

    Android Studio中的Gradle依赖深入讲解

    Android Studio由于使用了gradle的进行项目构建,使我们开发app方便很多,下面这篇文章主要给大家介绍了关于Android Studio中Gradle依赖的相关资料,文中通过示例...

    张明云6102022-08-04