如何从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);
当前回答
确保r.b ayout.themechanger没有背景色,因为默认情况下对话框有默认背景色。
你还需要添加dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));
最后
<style name="TransparentDialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
</style>
其他回答
如果你使用Kotlin,这段代码可以帮助你:
Objects.requireNonNull(dialog.window)
?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
添加以下代码
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
或者换成这个:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
按样式设置这些样式代码
<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>
它会使你的背景变暗。
确保r.b ayout.themechanger没有背景色,因为默认情况下对话框有默认背景色。
你还需要添加dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));
最后
<style name="TransparentDialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
</style>
我遇到过更简单的问题,我想出的解决方案是应用透明的背景主题。按照你的风格写出这些行
<item name="android:windowBackground">@drawable/blue_searchbuttonpopupbackground</item>
</style>
<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>
然后加上
android:theme="@style/Theme.Transparent"
在主清单文件中,在对话框活动的块内。
在您的对话框活动XML集
android:background= "#00000000"