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

    效果:

  • 相关阅读:
    OutputCache详解
    C#数值类型的转换
    C#变量类型转换
    C#和.net
    数组
    mvc
    C#部分基础知识
    项目开发-->高级功能汇总
    项目开发-->基础功能汇总
    C#基础篇
  • 原文地址:https://www.cnblogs.com/xiobai/p/13750028.html
Copyright © 2011-2022 走看看