栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android实现从底部弹出的Dialog的实例代码

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android实现从底部弹出的Dialog的实例代码

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的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/156434.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号