如何从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);
当前回答
使用这段代码,它是为我工作:
Dialog dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
dialog.show();
其他回答
不知何故,撒迦利亚的解决方案对我不起作用,所以我用下面的主题来解决这个问题…
<style name="DialogCustomTheme" parent="android:Theme.Holo.Dialog.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
可以将此主题设置为对话框,如下所示
final Dialog dialog = new Dialog(this, R.style.DialogCustomTheme);
享受! !
注意:不要使用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()选项。
在你的代码中试试这个:
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
它肯定会起作用……对我来说…!我的弗洛伊德
如果你扩展了DialogFrament类,你可以设置主题:
setStyle(DialogFragment.STYLE_NORMAL, R.style.customDialogTheme);
然后在styles.xml文件中创建自定义主题(参见@LongLv的参数回答)
不要忘记添加<item name="android:windowCloseOnTouchOutside">true</item>如果你想让用户在对话框外触摸时关闭对话框。
对话框弹出填充默认的黑色背景颜色或主题颜色,所以你需要设置透明的背景到对话框。试试下面的代码:-
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();