Android弹出自定义Dialog,android自定义Dialog实现底部弹窗

本文介绍了如何在Android中实现自定义Dialog并使其作为底部弹窗展示,避免直接使用popWindow,而是通过深入理解Dialog的源码,创建自定义类继承Dialog,并设置布局、属性,最终达到期望的效果。
摘要由CSDN通过智能技术生成

android自定义Dialog实现底部弹窗

拿到这个需求,很多人都是直接想用popWindow 实现,但是这样的效果我们完全可以根据系统的Dialog 自定义一个。

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setTitle("SSS");

builder.show();

这样就直接显示出一个对话框,但是,这个对话框在屏幕的中间,然后,我们去查看dialog的源码:

看dialog.show()里面判断了是否正在显示中,并没有和根布局有关系,看这个类的父类。里面的show()中:

public void show() {

if (mShowing) {

if (mDecor != null) {

if (mWindow.hasFeature(Window.FEATURE_ACTION_BAR)) {

mWindow.invalidatePanelMenu(Window.FEATURE_ACTION_BAR);

}

mDecor.setVisibility(View.VISIBLE);

}

return;

}

mCanceled = false;

if (!mCreated) {

dispatchOnCreate(null);

} else {

// Fill the DecorView in on any configuration changes that

// may have occured while it was removed from the WindowManager.

final Configuration config = mContext.getResources().getConfiguration();

mWindow.getDecorView().dispatchConfigurationChanged(config);

}

onStart();

mDecor = mWindow.getDecorView();

if (mActionBar == null && mWindow.hasFeature(Window.FEATURE_ACTION_BAR)) {

final ApplicationInfo info = mContext.getApplicationInfo();

mWindow.setDefaultIcon(info.icon);

mWindow.setDefaultLogo(info.logo);

mActionBar = new WindowDecorActionBar(this);

}

WindowManager.LayoutParams l = mWindow.getAttributes();

if ((l

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值