前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >adnroid仿miui的dialog

adnroid仿miui的dialog

作者头像
全栈程序员站长
发布2022-07-13 20:13:47
发布2022-07-13 20:13:47
84200
代码可运行
举报
运行总次数:0
代码可运行

大家好,又见面了,我是全栈君,祝每个程序员都可以多学几门语言。

先来看下效果图:

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

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

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

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

代码语言:javascript
代码运行次数:0
复制
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中加入下面代码就可以:

代码语言:javascript
代码运行次数:0
复制
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);
                }
            }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/118085.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年12月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档