AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.content);
// 加载布局 MainActivity.content 对应 MainActivity.this
time_view = View.inflate(MainActivity.content, R.layout.time_long, null);
count_tiime = (TextView) time_view.findViewById(R.id.count_tiime);
count_tiime.setText(hms);
builder.setView(time_view);
// 点击遮罩层不关闭 即弹窗的外部 builder.setCancelable(true); 对应点击外部可关闭
builder.setCancelable(false);
builder.create().show();
可自定义 time_long.xml 布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:text="开始记录时间"
android:textColor="#33b5e5"
android:textStyle="bold"></TextView>
<TextView
android:id="@+id/start_tiime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始记录时间"></TextView>
</LinearLayout>
<TextView
android:id="@+id/count_tiime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始时间"></TextView>
</LinearLayout>