Open xuxh6 opened 5 years ago
怎样正确的在Dialog中使用? How to use it correctly in Dialog?
怎样正确的在Dialog中使用? How to use it correctly in Dialog?
Hi! I've been using another library, but there are 2 solutions:
Every time you open a dialog, show another full-screen dialog with blur view. It's quite easy:
You can try to create an abstract dialog class that all your dialogs will extend, override methods show
and onDismiss
with onCancel
for showing and hiding your custom BlurDialog
Example:
abstract class BlurDialogFragment : DialogFragment() {
private var blurDialog: BlurDialog? = null
override fun show(manager: FragmentManager, tag: String?) {
initBlurDialog(manager.beginTransaction())?.let {
super.show(it, tag)
}
}
override fun show(transaction: FragmentTransaction, tag: String?): Int {
return initBlurDialog(transaction)?.let {
super.show(it, tag)
} ?: -1
}
override fun onCancel(dialog: DialogInterface) {
blurDialog?.dismiss()
super.onCancel(dialog)
}
override fun onDismiss(dialog: DialogInterface) {
blurDialog?.dismiss()
super.onDismiss(dialog)
}
private fun initBlurDialog(transaction: FragmentTransaction): FragmentTransaction? {
if (blurDialog != null)
return null
blurDialog = BlurDialog.getInstance()
transaction
.add(blurDialog!!, BlurDialogTag)
return transaction
}
}
Note!
If you decide to implement this idea, BlurDialog
is another dialog and you should declare and set appropriate style:
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.FullScreenDialogWithFadeStyle)
}
我在Dialog中使用!背景效果不对,看图片 I use it in Dialog! The background is not right. Look at the picture.