zoukankan      html  css  js  c++  java
  • Android-----自定义AlertDialog弹框

    需要使用弹框来实现加载效果,用的是别人的加载框架:

    repositories {
            google()
            jcenter()
            maven { url 'https://jitpack.io' } 
        }
    
    
    
    compile 'com.github.zzz40500:android-shapeLoadingView:1.0.3.2'  //内容加载展示(图形)

    自定义AlertDialog弹框布局:

    <?xml version="1.0" encoding="utf-8"?>
    <!--    数据加载中提示布局    -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:background="@drawable/dialog_background_dark"
        tools:context="com.org.huanjianmvp.Activity.ListDatas">
    
        <com.mingle.widget.LoadingView
            android:id="@+id/loadView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>

    写一个静态方法来返回自定义好的弹框:

    /**【加载框展示】**/
        public static AlertDialog AlertLoading(Context context){
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            AlertDialog dialog = builder.create();
            View dialogView = View.inflate(context, R.layout.loading,null);   //自定义弹框视图
            LoadingView loadingView = dialogView.findViewById(R.id.loadView);
            loadingView.setLoadingText("数据加载中. . .");
            dialog.setView(dialogView);
            dialog.getWindow().setDimAmount(0f);    //去掉遮罩层
            Window window = dialog.getWindow();
            WindowManager.LayoutParams layout = window.getAttributes();
            layout.alpha = 0.5f;
            window.setAttributes(layout);       //弹窗透明度设置
            dialog.setCancelable(false);        //点击弹框无法取消
            return dialog;
        }

    使用:

    AlertDialog dialog= AlertDialogUtils.AlertLoading(Login.this);
    
    dialog.show();    //展示
    
    dialog.dismiss();//关闭

    效果:

  • 相关阅读:
    Kubernetes基本概念之Volume
    Kubernetes对象之PersistentVolume,PersistentVolumeClaim和StorageClass
    SSDB高效能缓存系统
    python2升级python3
    pkg-config相关的常用指令
    CISSP考试经验分享
    如何在命令行添加换行符到git commit -m "xxx"
    为什么tcp-wrappers被Redhat Centos Fedora废弃?
    Docker 国内仓库和镜像
    shell脚本对代码执行时间的计时
  • 原文地址:https://www.cnblogs.com/xiobai/p/13750028.html
Copyright © 2011-2022 走看看