如何从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);
当前回答
在你的代码中试试这个:
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
它肯定会起作用……对我来说…!我的弗洛伊德
其他回答
使用这段代码,它是为我工作:
Dialog dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
dialog.show();
在我的案例中,解决方案是这样的:
final Drawable drawable = new ColorDrawable(android.graphics.Color.TRANSPARENT);
dialogAssignTag.getWindow().setBackgroundDrawable(drawable);
另外,在自定义对话框的xml文件中:
android:alpha="0.8"
如果你扩展了DialogFrament类,你可以设置主题:
setStyle(DialogFragment.STYLE_NORMAL, R.style.customDialogTheme);
然后在styles.xml文件中创建自定义主题(参见@LongLv的参数回答)
不要忘记添加<item name="android:windowCloseOnTouchOutside">true</item>如果你想让用户在对话框外触摸时关闭对话框。
这就是我用AlertDialog实现半透明的方法。
创建自定义样式:
<style name="TranslucentDialog" parent="@android:style/Theme.DeviceDefault.Dialog.Alert">
<item name="android:colorBackground">#32FFFFFF</item>
</style>
然后创建对话框:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.TranslucentDialog);
AlertDialog dialog = builder.create();
如果你想破坏对话框的黑暗背景,使用这个
dialog.getWindow().setDimAmount(0);