ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android-----自定义AlertDialog弹框

2020-10-12 09:02:59  阅读:258  来源: 互联网

标签:layout 自定义 弹框 AlertDialog dialog Android 加载


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

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

效果:

标签:layout,自定义,弹框,AlertDialog,dialog,Android,加载
来源: https://www.cnblogs.com/xiobai/p/13750028.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有