如何从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);
当前回答
我遇到过更简单的问题,我想出的解决方案是应用透明的背景主题。按照你的风格写出这些行
<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"
其他回答
注意:不要使用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()选项。
不知何故,撒迦利亚的解决方案对我不起作用,所以我用下面的主题来解决这个问题…
<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);
享受! !
在Kotlin中,你可以使用以下代码:
val dialog = Dialog(context)
dialog.window?.decorView?.background = null
使用这段代码,它是为我工作:
Dialog dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
dialog.show();
与zGnep相同的解决方案,但使用xml:
android:background="@null"