Android实现从底部弹出的Dialog的方法-创新互联

这篇文章将为大家详细讲解有关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的方法

关于“Android实现从底部弹出的Dialog的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


本文标题:Android实现从底部弹出的Dialog的方法-创新互联
转载源于:http://myzitong.com/article/dhsiei.html