Android实现底部弹出的对话框功能

  

<强>环境:

  
      <李>主机:WIN10李   <李>开发环境:Android Studio 2.2预览版3   
  

<强>说明:
  两种方法实现底部弹出的对话框:

  
      <李>对话框   <李> DialogFragment李   
  

推荐用DialogFragment

  

<>强效果图:

  

 Android实现底部弹出的对话框功能

  

布局文件dialog_select_call。xml:
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄盿ndroid: layout_width=癿atch_parent”   android: layout_height=癿atch_parent”比;      & lt;使用   android: id=癅 + id/layout_voice”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:背景=" @color/白”比;      & lt; TextView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentStart=" true "   android: layout_centerInParent=" true "   android: textSize=" 16 sp "   android:输入textColor=" @color/黑”   android: layout_marginLeft=" 16 dp "   android: layout_marginRight=" 16 dp "   android: layout_marginTop=" 16 dp "   android: layout_marginBottom=" 16 dp "   android:文本="语音课堂”/比;   & lt;/RelativeLayout>      & lt;视图   android: layout_width="宽和"   android: layout_height=" 0.1 dp "   android:背景=" # b4b4b4”   android: layout_marginLeft=" 16 dp "   android: layout_marginRight=?6 dp/比;      & lt;使用   android: id=癅 + id/layout_video”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:背景=" @color/白”比;      & lt; TextView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentStart=" true "   android: layout_centerInParent=" true "   android: textSize=" 16 sp "   android:输入textColor=" @color/黑”   android: layout_marginLeft=" 16 dp "   android: layout_marginRight=" 16 dp "   android: layout_marginTop=" 16 dp "   android: layout_marginBottom=" 16 dp "   android:文本="视频课堂”/比;   & lt;/RelativeLayout>      & lt;视图   android: layout_width="宽和"   android: layout_height=" 0.1 dp "   android:背景=" # b4b4b4”   android: layout_marginLeft=" 16 dp "   android: layout_marginRight=?6 dp/比;      & lt;使用   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:背景=" @color/白”比;      & lt;按钮   android: id=癅 + id/取消”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:文本="取消”   android: layout_marginLeft=" 16 dp "   android: layout_marginRight=" 16 dp "   android: layout_marginTop=" 16 dp "   android: layout_marginBottom=?6 dp/比;   & lt;/RelativeLayout>      & lt;/LinearLayout>   之前      

对话框实现源码:
  

  

初始化:
  

        私人空间dialogSelectCallInit () {   dialogSelectCall=new对话框(这个,R.style.DialogPopBottom);   视图膨胀=LayoutInflater.from(这).inflate (R.layout.dialog_select_call, null);   dialogSelectCall.setContentView(膨胀);      窗口dialogWindow=dialogSelectCall.getWindow ();   dialogWindow.setGravity (Gravity.BOTTOM);      WindowManager。LayoutParams lp=dialogWindow.getAttributes ();   lp。x=0;   lp。y=0;   lp。.widthPixels .getDisplayMetrics宽度=getresource () ();   dialogWindow.setAttributes (lp);      RelativeLayout layoutVoice=(使用)inflate.findViewById (R.id.layout_voice);   RelativeLayout layoutVideo=(使用)inflate.findViewById (R.id.layout_video);   按钮buttonCancel=(按钮)inflate.findViewById (R.id.cancel);      RxView.clicks (layoutVoice)   TimeUnit.SECONDS .throttleFirst (2)   .compose (this.bindUntilEvent (ActivityEvent.DESTROY))   .subscribe (v→{//dialogSelectCall.cancel ();   VoiceSessionActivity。startActivityCallOut(这个,userId);   });      RxView.clicks (layoutVideo)   TimeUnit.SECONDS .throttleFirst (2)   .compose (this.bindUntilEvent (ActivityEvent.DESTROY))   .subscribe (v→{//dialogSelectCall.cancel ();//VideoSessionActivity。startActivityCallOut(这个,userId);   });      RxView.clicks (buttonCancel)   TimeUnit.SECONDS .throttleFirst (2)   .compose (this.bindUntilEvent (ActivityEvent.DESTROY))   .subscribe (v→dialogSelectCall.cancel ());      RxView。触摸(layoutVoice motionEvent→{   dealLayoutTouch (layoutVoice motionEvent);   返回错误;   }).compose (this.bindUntilEvent (ActivityEvent.DESTROY) .subscribe (motionEvent→{});      RxView。触摸(layoutVideo motionEvent→{   dealLayoutTouch (layoutVideo motionEvent);   返回错误;   }).compose (this.bindUntilEvent (ActivityEvent.DESTROY) .subscribe (motionEvent→{});   }      私人空间dealLayoutTouch(视图v MotionEvent事件){   开关(event.getAction ()) {   案例MotionEvent.ACTION_DOWN:   v.setBackgroundColor(颜色。rgb (200、200、200));   打破;   案例MotionEvent.ACTION_UP:   v.setBackgroundColor (Color.WHITE);   打破;   }   }   

Android实现底部弹出的对话框功能