Closed namnguyen211 closed 2 years ago
Please be more specific, I'm not going to write all the code for you. Tell me what you tried in details and what's not working.
class MyClass :BottomSheetDialogFragment(){
private var _binding: MyClassViewBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = MyClassViewBinding.inflate(inflater, container, false)
val blurContainer = BlurView(requireContext())
blurContainer.id = BLUR_ID
blurContainer.addView(binding.root)
return blurContainer
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val blurView = view.findViewById<BlurView>(BLUR_ID)
blurView.setupWith(requireActivity().window.decorView as ViewGroup)
.setFrameClearDrawable(requireActivity().window.decorView.background)
.setBlurAlgorithm(RenderScriptBlur(requireContext()))
.setBlurRadius(10f)
}
}
this is my code. background not blur.
Your BlurView doesn't have a size:
val blurContainer = BlurView(requireContext())
Set proper LayoutParams or just put it in your XML
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentSinglePhotoViewBinding.inflate(inflater, container, false)
val blurContainer = BlurView(requireContext())
blurContainer.id = BLUR_ID
val param = ViewGroup.LayoutParams(
/*width*/
ViewGroup.LayoutParams.MATCH_PARENT, /*height*/
ViewGroup.LayoutParams.MATCH_PARENT,
)
blurContainer.layoutParams = param
blurContainer.addView(binding.root)
return blurContainer
}
i added LayoutParams but not works.
You also need to set .setBlurAutoUpdate(true)
as in Readme
val blurView = view.findViewById<BlurView>(BLUR_ID)
blurView.setupWith(requireActivity().window.decorView as ViewGroup)
.setFrameClearDrawable(requireActivity().window.decorView.background)
.setBlurAlgorithm(RenderScriptBlur(requireContext()))
.setHasFixedTransformationMatrix(true)
.setBlurAutoUpdate(true)
.setBlurRadius(20f)
it still not works
setHasFixedTransformationMatrix(false)
and post your XML layout.
Make sure it doesn't have a background that would cover blur or anything like that
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="100dp" android:layout_height="100dp" android:layout_centerInParent="true" android:background="@color/black" /> </RelativeLayout>
`package com.example.bottomsheetdialog
import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.android.material.bottomsheet.BottomSheetDialogFragment import eightbitlab.com.blurview.BlurView import eightbitlab.com.blurview.RenderScriptBlur
class BlurBottomSheetDialogFragment : BottomSheetDialogFragment() {
private val BLUR_ID = 514214;
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val blurContainer = BlurView(requireContext())
blurContainer.id = BLUR_ID
blurContainer.layoutParams = ViewGroup.LayoutParams(
/*width*/
ViewGroup.LayoutParams.MATCH_PARENT, /*height*/
ViewGroup.LayoutParams.MATCH_PARENT,
)
blurContainer.addView(inflater.inflate(R.layout.dialog_connect_wifi, container, false))
return blurContainer
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// this part is important to make injected background blur
val blurView = view.findViewById<BlurView>(BLUR_ID)
blurView.setupWith(requireActivity().window.decorView as ViewGroup)
.setFrameClearDrawable(requireActivity().window.decorView.background)
.setBlurAlgorithm(RenderScriptBlur(requireContext()))
.setHasFixedTransformationMatrix(false)
.setBlurAutoUpdate(true)
.setBlurRadius(10f)
}
}`
this is my file bottomsheet dialog
But what do you want to blur?
You have plain white background. Blurring it will produce plain white color, as you have on your dialog.
Try adding at least something to the bottom of your activity to see the blur.
Please include: 1) Library version: com.eightbitlab:blurview:1.6.6
Please, help me blur BottomSheetDialogFragment background.thanks