1. 效果截图

2. LoadingDialog代码

public class LoadingDialog extends Dialog {         private AnimationDrawable mAnimation;    private final String mLoadingTitle;    private final int layout;    public LoadingDialog(Context context, String content, int layout) {             super(context);        this.mLoadingTitle = content;        this.layout = layout;        //点击外围取消        setCanceledOnTouchOutside(true);    }    @Override    protected void onCreate(Bundle savedInstanceState) {             super.onCreate(savedInstanceState);        //设置窗口布局        setContentView(R.layout.progress_dialog);        ImageView mImageView = findViewById(R.id.loadingIv);        //设置动画资源        mImageView.setImageResource(layout);        mAnimation = (AnimationDrawable) mImageView.getDrawable();        // 启动动态图话        mImageView.postDelayed(mAnimation::start, 100);        TextView mLoadingTv = findViewById(R.id.loadingTv);        //设置加载文字        mLoadingTv.setText(mLoadingTitle);        // #00FFFFFF        //设置透明        getWindow().setBackgroundDrawableResource(R.color.transparent);    }}

3. 调用窗口代码

public class MainActivity extends AppCompatActivity {         private LoadingDialog loadingDialog;    @Override    protected void onCreate(Bundle savedInstanceState) {             super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        findViewById(R.id.show).setOnClickListener(v -> {                 if (loadingDialog == null) {                     //创建                loadingDialog = new LoadingDialog(MainActivity.this, "正在加载", R.drawable.anim_loading);            }            //调用            loadingDialog.show();        });    }}

4. LoadingDialog布局——progress_dialog.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:gravity="center"    android:orientation="vertical">    <ImageView        android:id="@+id/loadingIv"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:contentDescription="@string/loading" />    <TextView        android:id="@+id/loadingTv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textColor="@color/black"        android:textSize="20sp" />LinearLayout>

5. 调用窗口布局——activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:gravity="center"    android:orientation="vertical">    <Button        android:id="@+id/show"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="16dp"        android:background="@color/black"        android:text="@string/show"        android:textColor="#ffffff" />LinearLayout>

6. 动画文件——anim_loading.xml

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="false" >    <item        android:drawable="@drawable/loading_01"        android:duration="200"/>    <item        android:drawable="@drawable/loading_02"        android:duration="200"/>    <item        android:drawable="@drawable/loading_03"        android:duration="200"/>    <item        android:drawable="@drawable/loading_04"        android:duration="200"/>    <item        android:drawable="@drawable/loading_05"        android:duration="200"/>    <item        android:drawable="@drawable/loading_06"        android:duration="200"/>    <item        android:drawable="@drawable/loading_07"        android:duration="200"/>    <item        android:drawable="@drawable/loading_08"        android:duration="200"/>    <item        android:drawable="@drawable/loading_09"        android:duration="200"/>    <item        android:drawable="@drawable/loading_10"        android:duration="200"/>    <item        android:drawable="@drawable/loading_11"        android:duration="200"/>    <item        android:drawable="@drawable/loading_12"        android:duration="200"/>animation-list>

7. 透明色彩

<color name="transparent">#00FFFFFFcolor>

参考链接:https://www.runoob.com/w3cnote/android-tutorial-progressbar.html
源码及素材地址:https://github.com/WindSnowLi/android-tools
源码及素材地址:https://gitee.com/windsnowli/android-tools

更多相关文章

  1. ViewPagerIndicator使用
  2. android的ImageSwitcher和TextSwitcher
  3. 分页控件1
  4. android与js交互-jsbridge
  5. Android自动补全(二)
  6. Android常用代码
  7. Android中自定义Dialog样式
  8. android 安卓创建文件夹
  9. 三步搞定:Vue.js调用Android原生方法

随机推荐

  1. 在LinearLayout中嵌套RelativeLayout来设
  2. android ble connect slowly
  3. Android之查看外部依赖jar的源码
  4. 那些java半路转Android开发者现状;后悔转
  5. Android快速批量多渠道包的“蛋生”
  6. android webview 底层实现的逻辑
  7. android mapView
  8. android webservices sax 传输并解析xml
  9. Android善用预定义样式
  10. 使用反射调用android API中的hide方法