标题是,我似乎无法调暗我所做的自定义对话框的背景.无数解决方案在线提到了下面第一个代码段中的最后3行代码,这对对话框的UI没有任何影响.
请参阅以下代码:
- Dialog dialog = new Dialog(MainActivity.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.dialog);
- TextView textView = (TextView) dialog.findViewById(R.id.textView);
- textView.setText("Custom Text Example");
- dialog.show();
- WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
- layoutParams.dimAmount = .7f;
- dialog.getWindow().setAttributes(layoutParams);
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/progressDialogCustom"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/dialog_black"
- android:orientation="horizontal"
- android:padding="10dp" >
- <ProgressBar
- android:id="@+id/progressBar1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:gravity="center_vertical"
- android:textColor="@android:color/white"
- android:text="Updating Profile . . ." />
- </LinearLayout>
@ drawable / dialog_black文件如下:
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle" >
- <solid android:color="@android:color/background_dark" />
- <corners
- android:bottomLeftRadius="7dp"
- android:bottomRightRadius="7dp"
- android:topLeftRadius="7dp"
- android:topRightRadius="7dp" />
- <stroke
- android:width="1px"
- android:color="@android:color/darker_gray" />
- <padding
- android:bottom="5dp"
- android:left="5dp"
- android:right="5dp"
- android:top="5dp" />
- </shape>