Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我在Dialog中使用!I use it in Dialog! The background is not right. Look at the picture. #64

Open
xuxh6 opened this issue Jun 27, 2019 · 3 comments

Comments

@xuxh6
Copy link

xuxh6 commented Jun 27, 2019

我在Dialog中使用!背景效果不对,看图片
I use it in Dialog! The background is not right. Look at the picture.

@xuxh6
Copy link
Author

xuxh6 commented Jun 27, 2019

image

@xuxh6
Copy link
Author

xuxh6 commented Jun 27, 2019

怎样正确的在Dialog中使用?
How to use it correctly in Dialog?

@flaringapp
Copy link

怎样正确的在Dialog中使用?
How to use it correctly in Dialog?

Hi! I've been using another library, but there are 2 solutions:

  1. 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)
    }
  1. Create one dialog for blur and your content, a full-screen dialog, where you have to set all margins for content manually. I suppose 1st method is better and easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants