Bootstrap

Android自定义dialog宽高,自定义Dialog,指定宽高、背景色

AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.CustomDialog);

View inflate = LayoutInflater.from(context).inflate(R.layout.layout_custom_dialog, null, false);

builder.setView(inflate);

AlertDialog dialog = builder.create();

dialog.show();

R.style.CustomDialog

80%

@android:color/transparent

R.layout.layout_custom_dialog

layout 根布局的宽高属性都不会生效,最终宽度会由Dialog的style中的android:windowMinWidthMinor属性决定,高度会表现为wrap_content,即使设置不是wrap_content

android:layout_width="0dp"

android:layout_height="0dp"

android:background="@drawable/shape_dialog_bg"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="48dp"

android:gravity="center_vertical"

android:text="Title" />

android:layout_width="match_parent"

android:layout_height="48dp"

android:orientation="horizontal">

android:id="@+id/textView2"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:gravity="center"

android:text="Cancel" />

android:id="@+id/textView"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:gravity="center"

android:text="Confirm" />

;