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();//关闭

    效果:

  • 相关阅读:
    关于学习Knockoutjs--入门(一)
    h5移动端前端性能优化
    VS2015常用快捷键总结
    51nod1196 字符串的数量
    51nod1189 阶乘分数
    51nod1161 Partial Sums
    51nod1040 矩阵相乘结果的判断
    51nod 1125 交换机器的最小代价
    51nod 1120 机器人走方格 V3
    51nod 1040 最大公约数之和
  • 原文地址:https://www.cnblogs.com/xiobai/p/13750028.html
Copyright © 2011-2022 走看看