标题是,我似乎无法调暗我所做的自定义对话框的背景.无数解决方案在线提到了下面第一个代码段中的最后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>
解决方法
原文地址:https://www.jb51.cc/android/308867.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。