zoukankan      html  css  js  c++  java
  • adnroid仿miui的dialog

    先来看下效果图:



    当中show和dismiss的时候有动画效果。


    原先试过使用PopupWindow来做,可是使用的时候不是那么舒服,毕竟不是dialog嘛。

    所以这次尝试还是使用dialog来做 ,非常多地方是引用了系统源代码(源代码是最好的老师)


    首先看CustomDialog.java的构造函数:

    protected CustomDialog(Context context) {
            this(context, R.style.CustomDialog);
        }
    
        protected CustomDialog(Context context, int theme) {
            super(context, theme);
            mAlert = new AlertController(context, this, getWindow());
            
            Window window = getWindow();
            window.setGravity(Gravity.BOTTOM); // 设置window的位置为底部
            window.setWindowAnimations(R.style.AnimationDialog); // 设置window的动画
            window.setBackgroundDrawableResource(android.R.color.transparent); // 设置window背景透明
        }

     

    艾玛,不太会描写叙述,直接上源代码

    0资源分代码下载地址:http://download.csdn.net/detail/luck_apple/7735321


    源代码中有点小问题,addView功能没有实现,在AlertController中加入下面代码就可以:

    public void apply(AlertController dialog) {
                if (mTitle != null) {
                    dialog.setTitle(mTitle);
                }
                if (mMessage != null) {
                    dialog.setMessage(mMessage);
                }
                if (mPositiveButtonText != null) {
                    dialog.setButton(DialogInterface.BUTTON_POSITIVE, mPositiveButtonText,
                            mPositiveButtonListener, null);
                }
                if (mNegativeButtonText != null) {
                    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, mNegativeButtonText,
                            mNegativeButtonListener, null);
                }
                // addView的实现
                if (mView != null) {
                    if (mViewSpacingSpecified) {
                        dialog.setView(mView, mViewSpacingLeft, mViewSpacingTop, mViewSpacingRight,
                                mViewSpacingBottom);
                    } else {
                        dialog.setView(mView);
                    }
                }





  • 相关阅读:
    UVA
    UVA
    UVA
    UVA
    NLP介绍
    新建Springboot项目
    添加ssh密钥
    git 错误合集
    Git入门操作
    Hadoop MapReduce
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4077272.html
Copyright ? 2011-2022 开发猿


http://www.vxiaotou.com