CameraKit / blurkit-android

The missing Android blurring library. Fast blur-behind layout that parallels iOS.
MIT License
3.72k stars 309 forks source link

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

Open xuxh6 opened 5 years ago

xuxh6 commented 5 years ago

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

xuxh6 commented 5 years ago

image

xuxh6 commented 5 years ago

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

flaringapp commented 5 years ago

怎样正确的在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