如何从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.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
或者换成这个:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
对话框弹出填充默认的黑色背景颜色或主题颜色,所以你需要设置透明的背景到对话框。试试下面的代码:-
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();
ColorDrawable drawable = new ColorDrawable(ContextCompat.getColor(ctx, android.R.color.transparent));
dialog.getWindow().setBackgroundDrawable(drawable);
按样式设置这些样式代码
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
然后在下面简单地将false更改为true
<item name="android:backgroundDimEnabled">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()选项。