我已经制作了自定义对话框
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/dialog_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/dialog_text_padding"
android:paddingRight="@dimen/dialog_text_padding"
android:paddingTop="@dimen/dialog_text_padding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialog_heading"
tools:text="Permissions"
android:textStyle="bold"
android:textColor="@color/brand_color"
android:textSize="22sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialog_text"
android:clickable="true"
android:layout_marginTop="@dimen/padding_large"
android:textSize="18sp"
tools:text="This app determines your phone location and shares it with Google to server personalized alters for you. This allows for a better app pferformance"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="24dp"
android:id="@+id/okCancelView"
android:paddingTop="@dimen/dialog_text_padding"
android:paddingLeft="@dimen/dialog_text_padding"
>
<TextView
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/dialog_cancel"
android:layout_marginRight="@dimen/dialog_text_padding"
android:gravity="center"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
tools:text="OK"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="CANCEL"
android:padding="10dp"
android:layout_alignParentRight="true"
android:textColor="@color/dialog_heading"
android:gravity="center"/>
</RelativeLayout>
</LinearLayout>
我用简单的
来展示它Dialog d=new Dialog(this);
d.setContentView(R.layout.custom_dialog);
d.show();
但我的对话框占据了整个屏幕宽度(附图像)。为什么屏幕和对话框之间没有空格?
答案 0 :(得分:1)
Display display = ((Activity) ctx).getWindowManager()
.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
alert_dialog.getWindow().setLayout((int) (width * .89),
LayoutParams.WRAP_CONTENT);