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

    效果:

  • 相关阅读:
    [CSP-S模拟测试]:赛(贪心+三分)
    [CSP-S模拟测试]:联(小清新线段树)
    [CSP-S模拟测试]:z(模拟+map+小根堆)
    赛瓦维斯特定理
    [CSP-S模拟测试]:y(DP+bitset)
    [CSP-S模拟测试]:x(数学+并查集)
    [杂题]:staGame(博弈论+Trie树+DFS)
    [杂题]:group(状压DP+轮廓线)
    [CSP-S模拟测试]:w(树上DP)
    BZOJ4103 [Thu Summer Camp 2015]异或运算 【可持久化trie树】
  • 原文地址:https://www.cnblogs.com/xiobai/p/13750028.html
Copyright © 2011-2022 走看看