如何从Android对话框中删除黑色背景。这张图片显示了问题所在。
final Dialog dialog = new Dialog(Screen1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.themechanger);
如何从Android对话框中删除黑色背景。这张图片显示了问题所在。
final Dialog dialog = new Dialog(Screen1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.themechanger);
当前回答
如果你扩展了DialogFrament类,你可以设置主题:
setStyle(DialogFragment.STYLE_NORMAL, R.style.customDialogTheme);
然后在styles.xml文件中创建自定义主题(参见@LongLv的参数回答)
不要忘记添加<item name="android:windowCloseOnTouchOutside">true</item>如果你想让用户在对话框外触摸时关闭对话框。
其他回答
注意:不要使用builder来改变背景。
Dialog dialog = new Dialog.Builder(MainActivity.this)
.setView(view)
.create();
dialog.show();dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
改变
Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.show();
使用对话框时。builder,它没有给出getWindow()选项。
ColorDrawable drawable = new ColorDrawable(ContextCompat.getColor(ctx, android.R.color.transparent));
dialog.getWindow().setBackgroundDrawable(drawable);
添加以下代码
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
或者换成这个:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
与zGnep相同的解决方案,但使用xml:
android:background="@null"
对话框弹出填充默认的黑色背景颜色或主题颜色,所以你需要设置透明的背景到对话框。试试下面的代码:-
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.splash);
dialog.show();