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);
                    }
                }





  • 相关阅读:
    MFC中L, _T(),TEXT,_TEXT区别以及含义
    Qt5完美解决 界面显示中文乱码
    TCP三次握手四次挥手详解
    TCP 长连接与短连接的区别
    Servlet 生命周期、工作原理
    Java反射的三种实现方式
    apache httpclient 4.5 兼容 http https
    mysql千万级大数据SQL查询优化
    Java String字符串补0或空格
    mysql存储过程
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4077272.html
Copyright © 2011-2022 走看看