皋鹏 發表於 2020-5-8 17:04:00

Android开发 BottomSheetDialogFragment底部弹出的对话框

<h1><span style="color: rgba(0, 128, 128, 1)">前言</span></h1>
<p>   BottomSheetDialogFragment是基于DialogFragment封装的,如果你不太了解DialogFragment,可以参考另一篇博客<span role="heading" aria-level="2">Android开发 DialogFragment对话框详解</span></p>
<h1><span style="color: rgba(22, 145, 121, 1)">基本使用代码</span></h1>
<pre class="highlighter-hljs" data-dark-theme="true"><code>import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.lwlx.ui.main.databinding.MainDialogSelectBinding

class MyBottomSheetDialogFragment: BottomSheetDialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      val binding = MainDialogSelectBinding.inflate(inflater)
      return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
    }
}</code></pre>
<h2><span style="color: rgba(35, 111, 161, 1)">显示对话框</span></h2>
<pre class="highlighter-hljs" data-dark-theme="true"><code>private fun showDeleteTipsDialog(){
    val dialog = MyBottomSheetDialogFragment()
    dialog.show(supportFragmentManager, "a")
}</code></pre>
<h1><span style="color: rgba(22, 145, 121, 1)">自定义<strong>DialogFragment</strong>实现底部弹出对话框</span></h1>
<p><strong><span style="color: rgba(0, 0, 0, 1)">这个例子其实之前这个博客原来的内容,但是因为后续有了BottomSheetDialogFragment,所以自己实现其实没有意义了。但是保留代码可以大家一个参考,你可以举一反三实现其他位置的对话框弹出。</span></strong></p>
<h2><span style="color: rgba(35, 111, 161, 1)">效果图</span></h2>
<p><span style="color: rgba(0, 128, 128, 1)"><img src="https://img2020.cnblogs.com/blog/1497956/202005/1497956-20200508165329365-1783240948.png" alt=""></span></p>
<h2><span style="color: rgba(35, 111, 161, 1)">代码部分</span></h2>
<p><span style="color: rgba(0, 0, 0, 1)">dialog_bottom_single.xml</span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;?</span><span style="color: rgba(255, 0, 255, 1)">xml version="1.0" encoding="utf-8"</span><span style="color: rgba(0, 0, 255, 1)">?&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">androidx.constraintlayout.widget.ConstraintLayout
    </span><span style="color: rgba(255, 0, 0, 1)">xmlns:android</span><span style="color: rgba(0, 0, 255, 1)">="http://schemas.android.com/apk/res/android"</span><span style="color: rgba(255, 0, 0, 1)">
    xmlns:app</span><span style="color: rgba(0, 0, 255, 1)">="http://schemas.android.com/apk/res-auto"</span><span style="color: rgba(255, 0, 0, 1)">
    android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="match_parent"</span><span style="color: rgba(255, 0, 0, 1)">
    android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="wrap_content"</span><span style="color: rgba(255, 0, 0, 1)">
    android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/root_layout"</span><span style="color: rgba(255, 0, 0, 1)">
    android:background</span><span style="color: rgba(0, 0, 255, 1)">="@drawable/bg_while_rectangle_radius"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>

    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">TextView
      </span><span style="color: rgba(255, 0, 0, 1)">android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/left_btn"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="0dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="wrap_content"</span><span style="color: rgba(255, 0, 0, 1)">
      android:gravity</span><span style="color: rgba(0, 0, 255, 1)">="left|center_vertical"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingLeft</span><span style="color: rgba(0, 0, 255, 1)">="25dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingTop</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingBottom</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textColor</span><span style="color: rgba(0, 0, 255, 1)">="@color/color_181818"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textSize</span><span style="color: rgba(0, 0, 255, 1)">="18sp"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintTop_toTopOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintLeft_toLeftOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintRight_toLeftOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/title"</span> <span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">TextView
      </span><span style="color: rgba(255, 0, 0, 1)">android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/title"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="0dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="wrap_content"</span><span style="color: rgba(255, 0, 0, 1)">
      android:gravity</span><span style="color: rgba(0, 0, 255, 1)">="center"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingTop</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingBottom</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:singleLine</span><span style="color: rgba(0, 0, 255, 1)">="true"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textColor</span><span style="color: rgba(0, 0, 255, 1)">="@color/color_181818"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textSize</span><span style="color: rgba(0, 0, 255, 1)">="18sp"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintTop_toTopOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintLeft_toRightOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/left_btn"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintRight_toLeftOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/right_btn"</span> <span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">TextView
      </span><span style="color: rgba(255, 0, 0, 1)">android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/right_btn"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="0dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="wrap_content"</span><span style="color: rgba(255, 0, 0, 1)">
      android:gravity</span><span style="color: rgba(0, 0, 255, 1)">="right|center_vertical"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingTop</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingRight</span><span style="color: rgba(0, 0, 255, 1)">="25dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:paddingBottom</span><span style="color: rgba(0, 0, 255, 1)">="13dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textColor</span><span style="color: rgba(0, 0, 255, 1)">="@color/color_181818"</span><span style="color: rgba(255, 0, 0, 1)">
      android:textSize</span><span style="color: rgba(0, 0, 255, 1)">="18sp"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintTop_toTopOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintLeft_toRightOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/title"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintRight_toRightOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span> <span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">View
      </span><span style="color: rgba(255, 0, 0, 1)">android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/line"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="0dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="1dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:background</span><span style="color: rgba(0, 0, 255, 1)">="@color/color_72"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintTop_toBottomOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/title"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintLeft_toLeftOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintRight_toRightOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">ListView
      </span><span style="color: rgba(255, 0, 0, 1)">android:id</span><span style="color: rgba(0, 0, 255, 1)">="@+id/content_list"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_width</span><span style="color: rgba(0, 0, 255, 1)">="0dp"</span><span style="color: rgba(255, 0, 0, 1)">
      android:layout_height</span><span style="color: rgba(0, 0, 255, 1)">="wrap_content"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintTop_toBottomOf</span><span style="color: rgba(0, 0, 255, 1)">="@id/line"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintLeft_toLeftOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(255, 0, 0, 1)">
      app:layout_constraintRight_toRightOf</span><span style="color: rgba(0, 0, 255, 1)">="parent"</span><span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">androidx.constraintlayout.widget.ConstraintLayout</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p><span style="color: rgba(0, 0, 0, 1)">bg_while_rectangle_radius.xml</span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;?</span><span style="color: rgba(255, 0, 255, 1)">xml version="1.0" encoding="utf-8"</span><span style="color: rgba(0, 0, 255, 1)">?&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">shape </span><span style="color: rgba(255, 0, 0, 1)">xmlns:android</span><span style="color: rgba(0, 0, 255, 1)">="http://schemas.android.com/apk/res/android"</span><span style="color: rgba(255, 0, 0, 1)">
    android:shape</span><span style="color: rgba(0, 0, 255, 1)">="rectangle"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">solid </span><span style="color: rgba(255, 0, 0, 1)">android:color</span><span style="color: rgba(0, 0, 255, 1)">="@color/ColorWhite"</span><span style="color: rgba(0, 0, 255, 1)">/&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">corners </span><span style="color: rgba(255, 0, 0, 1)">android:topLeftRadius</span><span style="color: rgba(0, 0, 255, 1)">="10dp"</span><span style="color: rgba(255, 0, 0, 1)"> android:topRightRadius</span><span style="color: rgba(0, 0, 255, 1)">="10dp"</span><span style="color: rgba(0, 0, 255, 1)">/&gt;</span>

<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">shape</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<h2>Java代码部分</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.content.Context;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.content.DialogInterface;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.graphics.drawable.ColorDrawable;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.os.Bundle;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.text.TextUtils;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.Gravity;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.LayoutInflater;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.View;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.ViewGroup;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.WindowManager;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.AdapterView;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.ArrayAdapter;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.ListView;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.TextView;

</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.annotation.NonNull;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.annotation.Nullable;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.constraintlayout.widget.ConstraintLayout;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.fragment.app.DialogFragment;

</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> net.wt.gate.R;

</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.List;

</span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
* content: 底部显示的单选对话框
* time: 2020-3-16
*
* </span><span style="color: rgba(128, 128, 128, 1)">@author</span><span style="color: rgba(0, 128, 0, 1)">: zhouqiang
</span><span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span> BottomSingleDialog&lt;T&gt; <span style="color: rgba(0, 0, 255, 1)">extends</span><span style="color: rgba(0, 0, 0, 1)"> DialogFragment {
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> ConstraintLayout mRootLayout;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> TextView mLeftBtn;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> TextView mTitle;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> TextView mRightBtn;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> ListView mContentList;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> OnBuildView mOnBuildView;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span> OnBottomSingleDialogListener&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> mListener;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span> BottomSingleDialogAdapter&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> mAdapter;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String mTitleContent;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String mLeftContent;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String mRightContent;
    </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> mSelectedPosition;

    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> BottomSingleDialog() {

    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> BottomSingleDialog(Context context, String title, String left, String right, <span style="color: rgba(0, 0, 255, 1)">int</span> resource, @NonNull List&lt;T&gt; dataList, OnBuildView&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> onBuildView) {
      mTitleContent </span>=<span style="color: rgba(0, 0, 0, 1)"> title;
      mLeftContent </span>=<span style="color: rgba(0, 0, 0, 1)"> left;
      mRightContent </span>=<span style="color: rgba(0, 0, 0, 1)"> right;
      mOnBuildView </span>=<span style="color: rgba(0, 0, 0, 1)"> onBuildView;
      mAdapter </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> BottomSingleDialogAdapter&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)">(context, resource, dataList);

    }


    @Nullable
    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span> inflater.inflate(R.layout.dialog_bottom_single, container, <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">);
    }

    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
      </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onViewCreated(view, savedInstanceState);
      mRootLayout </span>=<span style="color: rgba(0, 0, 0, 1)"> (ConstraintLayout) view.findViewById(R.id.root_layout);
      mLeftBtn </span>=<span style="color: rgba(0, 0, 0, 1)"> (TextView) view.findViewById(R.id.left_btn);
      mTitle </span>=<span style="color: rgba(0, 0, 0, 1)"> (TextView) view.findViewById(R.id.title);
      mRightBtn </span>=<span style="color: rgba(0, 0, 0, 1)"> (TextView) view.findViewById(R.id.right_btn);
      mContentList </span>=<span style="color: rgba(0, 0, 0, 1)"> (ListView) view.findViewById(R.id.content_list);
      mContentList.setAdapter(mAdapter);

      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">TextUtils.isEmpty(mTitleContent)) {
            mTitle.setText(mTitleContent);

      }
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">TextUtils.isEmpty(mLeftContent)) {
            mLeftBtn.setText(mLeftContent);

      }
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">TextUtils.isEmpty(mRightContent)) {
            mRightBtn.setText(mRightContent);

      }
      initListener();
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mListener != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
            mListener.onViewCreated(view, </span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
      }

    }

    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onStart() {
      </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onStart();
      WindowManager.LayoutParams params </span>=<span style="color: rgba(0, 0, 0, 1)"> getDialog().getWindow().getAttributes();
      params.width </span>= ViewGroup.LayoutParams.MATCH_PARENT;<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">设置宽度为铺满</span>
      params.gravity =<span style="color: rgba(0, 0, 0, 1)"> Gravity.BOTTOM;
      getDialog().getWindow().setAttributes((WindowManager.LayoutParams) params);
      getDialog().getWindow().setBackgroundDrawable(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> ColorDrawable(getContext().getResources().getColor(R.color.transparent)));
    }

    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onResume() {
      </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onResume();
    }

    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onStop() {
      </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onStop();
    }

    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onDestroy() {
      </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onDestroy();
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> ConstraintLayout getRootLayout() {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> mRootLayout;
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> TextView getLeftBtn() {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> mLeftBtn;
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> TextView getTitle() {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> mTitle;
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> TextView getRightBtn() {
      </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> mRightBtn;
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setOnBottomSingleDialogListener(OnBottomSingleDialogListener&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> listener) {
      mListener </span>=<span style="color: rgba(0, 0, 0, 1)"> listener;
    }

    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
   * 设置选中item
   *
   * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> position
   </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setSelectedItem(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> position) {
      mSelectedPosition </span>=<span style="color: rgba(0, 0, 0, 1)"> position;
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mAdapter == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
      }
      mAdapter.notifyDataSetChanged();
    }

    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
   * 更新列表内容
   </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> listNotifyDataSetChanged() {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mAdapter == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
      }
      mAdapter.notifyDataSetChanged();
    }

    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
   * 设置指定item数量的高度
   *
   * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> targetCount
   </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setItemCountHeight(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> targetCount) {
      mContentList.post(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Runnable() {
            @Override
            </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> run() {
                View view </span>= mContentList.getChildAt(0<span style="color: rgba(0, 0, 0, 1)">);
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (view == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                  </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
                }
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mContentList.getCount() &lt;<span style="color: rgba(0, 0, 0, 1)"> targetCount) {
                  </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
                }
                ViewGroup.LayoutParams layoutParams </span>=<span style="color: rgba(0, 0, 0, 1)"> mContentList.getLayoutParams();
                layoutParams.height </span>= view.getHeight() *<span style="color: rgba(0, 0, 0, 1)"> targetCount;
                mContentList.setLayoutParams(layoutParams);
            }
      });
    }

    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
   * 设置是否点击外部取消Dialog
   * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> isCanceledOnTouchOutside
   </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setCanceledOnTouchOutside(<span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> isCanceledOnTouchOutside) {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (getDialog() != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
            getDialog().setCanceledOnTouchOutside(isCanceledOnTouchOutside);
      }
    }

    </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> initListener() {
      mLeftBtn.setOnClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> View.OnClickListener() {
            @Override
            </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onClick(View v) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mListener != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                  mListener.onClickLeftBtn(BottomSingleDialog.</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
                }
            }
      });
      mRightBtn.setOnClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> View.OnClickListener() {
            @Override
            </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onClick(View v) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mListener != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                  mListener.onClickRightBtn(BottomSingleDialog.</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
                }
            }
      });
      getDialog().setOnCancelListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DialogInterface.OnCancelListener() {
            @Override
            </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onCancel(DialogInterface dialog) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mListener != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                  mListener.onCancel(BottomSingleDialog.</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
                }

            }
      });
      mContentList.setOnItemClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> AdapterView.OnItemClickListener() {
            @Override
            </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onItemClick(AdapterView&lt;?&gt; parent, View view, <span style="color: rgba(0, 0, 255, 1)">int</span> position, <span style="color: rgba(0, 0, 255, 1)">long</span><span style="color: rgba(0, 0, 0, 1)"> id) {
                </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mListener != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                  mListener.onClickItem(position, view, BottomSingleDialog.</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
                }
            }
      });


    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">abstract</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">class</span> OnBottomSingleDialogListener&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> {
      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 对话框View在创建的时候回调,在这个回调里,你可以修改对话框所有View的Ui效果
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> view
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dialog
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onViewCreated(View view, BottomSingleDialog&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {

      }

      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 左边按钮点击
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dialog
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClickLeftBtn(BottomSingleDialog&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {

      }

      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 右边按钮点击
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dialog
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClickRightBtn(BottomSingleDialog&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {

      }

      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 点击ListView中的item
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> position 点击位置
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> itemView 点击itemView
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dialog
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClickItem(<span style="color: rgba(0, 0, 255, 1)">int</span> position, View itemView, BottomSingleDialog&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {

      }

      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 对话框取消
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dialog
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onCancel(BottomSingleDialog&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {

      }

    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">interface</span> OnBuildView&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> {
      </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
         * 组装view并且返回
         *
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> position         当前位置
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> selectedPosition 当前选中item位置
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> parent         父类布局
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> layoutRes      导入的布局id
         * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> dataList         导入数据集合
         * </span><span style="color: rgba(128, 128, 128, 1)">@return</span>
         <span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
      View onBuildView(</span><span style="color: rgba(0, 0, 255, 1)">int</span> position, <span style="color: rgba(0, 0, 255, 1)">int</span> selectedPosition, @NonNull ViewGroup parent, <span style="color: rgba(0, 0, 255, 1)">int</span> layoutRes, List&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> dataList);
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span> BottomSingleDialogAdapter&lt;T&gt; <span style="color: rgba(0, 0, 255, 1)">extends</span> ArrayAdapter&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> {
      </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">int</span> layoutRes = 0<span style="color: rgba(0, 0, 0, 1)">;
      </span><span style="color: rgba(0, 0, 255, 1)">private</span> List&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> list;


      </span><span style="color: rgba(0, 0, 255, 1)">public</span> BottomSingleDialogAdapter(@NonNull Context context, <span style="color: rgba(0, 0, 255, 1)">int</span> resource, @NonNull List&lt;T&gt;<span style="color: rgba(0, 0, 0, 1)"> objects) {
            </span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">(context, resource, objects);
            layoutRes </span>=<span style="color: rgba(0, 0, 0, 1)"> resource;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.list =<span style="color: rgba(0, 0, 0, 1)"> objects;
      }

      @NonNull
      @Override
      </span><span style="color: rgba(0, 0, 255, 1)">public</span> View getView(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> position, @Nullable View convertView, @NonNull ViewGroup parent) {
            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (mOnBuildView != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
                </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> mOnBuildView.onBuildView(position, mSelectedPosition, parent, layoutRes, list);
            }
            </span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.getView(position, convertView, parent);
      }
    }
}</span></pre>
</div>
<h1><span style="color: rgba(0, 128, 128, 1)">使用例子</span></h1>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> initAllReadDialog() {
    List</span>&lt;String&gt; list = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
    list.add(getString(R.string.mark_all_as_read));
    list.add(getString(R.string.cancel));
    mAllReadDialog </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> BottomSingleDialog&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">(getContext(),
            getString(R.string.mark_all_notifications_of_a_message_as_read),
            </span>""<span style="color: rgba(0, 0, 0, 1)">,
            </span>""<span style="color: rgba(0, 0, 0, 1)">,
            R.layout.item_all_read_dialog,
            list, </span><span style="color: rgba(0, 0, 255, 1)">new</span> BottomSingleDialog.OnBuildView&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">() {
      @Override
      </span><span style="color: rgba(0, 0, 255, 1)">public</span> View onBuildView(<span style="color: rgba(0, 0, 255, 1)">int</span> position, <span style="color: rgba(0, 0, 255, 1)">int</span> selectedPosition, @NonNull ViewGroup parent, <span style="color: rgba(0, 0, 255, 1)">int</span> layoutRes, List&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)"> dataList) {
            View view </span>= LayoutInflater.from(parent.getContext()).inflate(layoutRes, parent, <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">);
            TextView textView </span>=<span style="color: rgba(0, 0, 0, 1)"> view.findViewById(R.id.text);
            textView.setText(dataList.get(position));
            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (position == 0<span style="color: rgba(0, 0, 0, 1)">) {
                textView.setTextColor(getResources().getColor(R.color.color_text_yellow));
            } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
                textView.setTextColor(getResources().getColor(R.color.color_181818));
            }
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> view;
      }
    });
    mAllReadDialog.setOnBottomSingleDialogListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span> BottomSingleDialog.OnBottomSingleDialogListener&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)">() {
      @Override
      </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onViewCreated(View view, BottomSingleDialog&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {
            dialog.getLeftBtn().setVisibility(View.GONE);
            dialog.getRightBtn().setVisibility(View.GONE);
            dialog.getTitle().setTextSize(</span>16<span style="color: rgba(0, 0, 0, 1)">);
            dialog.getTitle().setTextColor(getResources().getColor(R.color.gray99));
            ViewGroup.LayoutParams layoutParams </span>=<span style="color: rgba(0, 0, 0, 1)"> dialog.getTitle().getLayoutParams();
            layoutParams.height </span>= UnitConversionUtil.dip2px(getContext(), 50<span style="color: rgba(0, 0, 0, 1)">);
            dialog.getTitle().setLayoutParams(layoutParams);
      }

      @Override
      </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClickItem(<span style="color: rgba(0, 0, 255, 1)">int</span> position, View itemView, BottomSingleDialog&lt;String&gt;<span style="color: rgba(0, 0, 0, 1)"> dialog) {
            mAllReadDialog.dismiss();
            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (position == 0<span style="color: rgba(0, 0, 0, 1)">) {
                mMessageViewModel.setMessageAllRead();
                </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
            }
      }

    });
}
   
    </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> show() {
      mAllReadDialog.show(getChildFragmentManager(), </span>"AllReadDialog"<span style="color: rgba(0, 0, 0, 1)">);
    }
    </span></pre>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>End</p>

</div>
<div id="MySignature" role="contentinfo">
    <div style="text-align: center">
    <p style="color:orange;font-size:16px;" >本文来自博客园,作者:观心静 ,转载请注明原文链接:https://www.cnblogs.com/guanxinjing/p/12851626.html </p>
    <div style="color:orange;font-size:16px;">本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。 </div>
</div><br><br>
来源:https://www.cnblogs.com/guanxinjing/p/12851626.html
頁: [1]
查看完整版本: Android开发 BottomSheetDialogFragment底部弹出的对话框