如何从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);
当前回答
如果你扩展了DialogFrament类,你可以设置主题:
setStyle(DialogFragment.STYLE_NORMAL, R.style.customDialogTheme);
然后在styles.xml文件中创建自定义主题(参见@LongLv的参数回答)
不要忘记添加<item name="android:windowCloseOnTouchOutside">true</item>如果你想让用户在对话框外触摸时关闭对话框。
其他回答
如果你使用Kotlin,这段代码可以帮助你:
Objects.requireNonNull(dialog.window)
?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
与zGnep相同的解决方案,但使用xml:
android:background="@null"
Kotlin创建透明背景对话框的方法:
Dialog(activity!!, R.style.LoadingIndicatorDialogStyle)
.apply {
// requestWindowFeature(Window.FEATURE_NO_TITLE)
setCancelable(true)
setContentView(R.layout.define_your_custom_view_id_here)
//access your custom view buttons/editText like below.z
val createBt = findViewById<TextView>(R.id.clipboard_create_project)
val cancelBt = findViewById<TextView>(R.id.clipboard_cancel_project)
val clipboard_et = findViewById<TextView>(R.id.clipboard_et)
val manualOption =
findViewById<TextView>(R.id.clipboard_manual_add_project_option)
//if you want to perform any operation on the button do like this
createBt.setOnClickListener {
//handle your button click here
val enteredData = clipboard_et.text.toString()
if (enteredData.isEmpty()) {
Utils.toast("Enter project details")
} else {
navigateToAddProject(enteredData, true)
dismiss()
}
}
cancelBt.setOnClickListener {
dismiss()
}
manualOption.setOnClickListener {
navigateToAddProject("", false)
dismiss()
}
show()
}
在style.xml中创建LoadingIndicatorDialogStyle,如下所示:
<style name="LoadingIndicatorDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<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:statusBarColor">@color/black_transperant</item>
<item name="android:layout_gravity">center</item>
<item name="android:background">@android:color/transparent</item>
<!--<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>-->
</style>
不知何故,撒迦利亚的解决方案对我不起作用,所以我用下面的主题来解决这个问题…
<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);
享受! !
使用这段代码,它是为我工作:
Dialog dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
dialog.show();