1.点击按钮(按钮的点击事件在此不在赘述,接下来直接写底部弹框的实现方式和样式的设计)
2.弹框
Dialog dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
//填充对话框的布局
inflate = LayoutInflater.from(context).inflate(R.layout.dialog_layout, null);
// setCancelable(iscancelable);//点击外部不可dismiss
//setCanceledonTouchOutside(isBackCanCelable);
//初始化控件
spinner = (Spinner) inflate.findViewById(R.id.sp);
beizhu = (TextView) inflate.findViewById(R.id.beizhu);
btn_cancel = (Button) inflate.findViewById(R.id.btn_cancel);
btn_ok = (Button) inflate.findViewById(R.id.btn_ok);
//将布局设置给Dialog
taskProgress.setContentView(inflate);
//获取当前Activity所在的窗体
Window dialogWindow = taskProgress.getWindow();
//设置Dialog从窗体底部弹出
dialogWindow.setGravity(Gravity.BOTTOM);
//获得窗体的属性
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//如果没有这行代码,弹框的内容会自适应,而不会充满父控件
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.y = 40;//设置Dialog距离底部的距离
//将属性设置给窗体
dialogWindow.setAttributes(lp);
dialog .show();//显示对话框
在需要消失地方直接
dialog.dismiss();
3.窗口的样式
- @android:color/transparent
- @null
- true
- @null
- true
- true
- true
- @style/ActionSheetDialogAnimation
- @anim/actionsheet_dialog_in
- @anim/actionsheet_dialog_out
4.窗口出现和消失的效果
对话框出现动画代码:
对话框消失的代码:
5.弹框的整体布局
6.lin_style样式
7.button_style样式
6.效果图
总结
以上所述是小编给大家介绍的Android实现从底部弹出的Dialog的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!



