skip to Main Content

I am trying to apply the following in order to help blur the background behind my dialog box which currently has a transparent background: Blur Background Behind AlertDialog

Only issue is, when the following section of code is applied inside the launch of my dialog box following an OnClick Method in my MainActivity.java:

‘Bitmap map=takeScreenShot(BlurImageView.this);
‘Bitmap fast=fastblur(map, 10);’

There is a red line under ‘map, 10’ with the error: ‘fastblur(android.graphics.Bitmap, float, int)’ in ‘anonymous class’ cannot be applied to ‘(android.graphics.Bitmap, int)’

Does anybody know what I might need do to eliminate this error please? Everything else seems to be fine, bar for that small snippet of code.

I can provide the rest of my MainActivity code if required? Unless anybody knows of a better way to blur the background under a dialog box in 2022?

Many thanks.

2

Answers


  1. Chosen as BEST ANSWER

    I have managed to seek and apply a solution now, so thank you for your help! It relies on the method whereby a screenshot is taken of the Activity before the Dialog Box is opened, followed by a blurring of the screenshot image and placement of it behind the Dialog Box. It's not always the quickest on the Emulator (it is yet to be trialled on my own Smartphone, for instance), but it does look good and the level of blurring effect can be tailored to specific needs. I'm fairly sure the solution is posted on a separate thread on this site, for those interested.


  2. i have done this by using framelayout.
    Here is the XML part for this.

    <?xml version="1.0" encoding="utf-8"?>
    
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="26dp"
            android:elevation="8dp"
            app:cardCornerRadius="8dp"
            app:cardUseCompatPadding="true">
    
            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                android:orientation="vertical">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/tvClassificationOP"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        android:layout_weight="1"
                        android:text="@string/event_name"
                        android:textColor="@color/black"
                        android:textSize="18sp"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
                    <androidx.appcompat.widget.AppCompatImageView
                        android:id="@+id/imgEditCalendar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="16dp"
                        android:src="@drawable/ic_edit"
                        app:layout_constraintEnd_toStartOf="@+id/imgDelete"
                        app:layout_constraintTop_toTopOf="parent" />
    
                    <androidx.appcompat.widget.AppCompatImageView
                        android:id="@+id/imgDeleteCalendar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="16dp"
                        android:src="@drawable/ic_delete"
                        app:layout_constraintEnd_toStartOf="@+id/imgShare"
                        app:layout_constraintTop_toTopOf="parent" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/tvLocationOps"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        android:layout_weight="1"
                        android:text="@string/training"
                        android:textColor="@color/black"
                        android:textSize="12sp"
                        app:layout_constraintBottom_toTopOf="@+id/tvTDutyimeOps"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/layoutToHide" />
    
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/tvtimeDialog"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="16dp"
                        android:text="@string/_20_12_2021_to_24_12_2021"
                        android:textColor="@color/black"
                        android:textSize="12sp"
                        app:layout_constraintBottom_toBottomOf="@id/tvLocationOps"
                        app:layout_constraintEnd_toEndOf="parent" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/layoutToHide"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
    
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/tvOpLocationOps"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        android:text="@string/london"
                        android:textColor="@color/black"
                        android:textSize="14sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
    
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="16dp"
                        android:text="@string/it_is_a_long_established_fact_that_a_reader_will_be_distracted_by_the_readable_content_of_a_page_layout"
                        android:textColor="@color/black"
                        android:textSize="14sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
    
                </LinearLayout>
    
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
    
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/closebtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="16dp"
                        android:layout_marginBottom="16dp"
                        android:text="@string/close"
                        android:textColor="@color/primarydark"
                        android:textSize="18sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
    
                </LinearLayout>
    
            </androidx.appcompat.widget.LinearLayoutCompat>
    
    
        </androidx.cardview.widget.CardView>
    </FrameLayout>
    

    And here is the Code part where i have set the background of the dialog transparent.

        class CalenderDialog : DialogFragment() {
        
            companion object {
                private var timedate: String? = null
                const val TAG = "Dialog"
                fun newInstance(): CalenderDialog {
                    val fragment = CalenderDialog()
                    return fragment
                }
            }
        
            override fun onCreateView(
                inflater: LayoutInflater,
                container: ViewGroup?,
                savedInstanceState: Bundle?
            ): View? {
                return inflater.inflate(R.layout.layout_date_dialog, container, false)
            }
        
            override fun onStart() {
                super.onStart()
        
                dialog?.window?.setLayout(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT
                )
        
     //this line will make the background behind the dialog transparent           dialog?.getWindow()?.setBackgroundDrawableResource(android.R.color.transparent);
                dialog?.setCanceledOnTouchOutside(false)
        
                val imgClosedlg = dialog?.findViewById(R.id.closebtn) as TextView
                val imgDelete = dialog?.findViewById(R.id.imgDeleteCalendar) as ImageView
                val time = dialog?.findViewById(R.id.tvtimeDialog) as TextView
                // time.text = timedate
        
                imgClosedlg.setOnClickListener {
                    dialog?.dismiss()
                }
        
                imgEditCalendar.setOnClickListener {
                    (activity as MainActivity).navigateToFragment(
                        AddEventFragment(),
                        true,
                        "AddEventFragment"
                    )
                    dialog?.dismiss()
                }
        
                imgDelete.setOnClickListener {
                    dialog?.dismiss()
                    val fm: androidx.fragment.app.FragmentManager? = fragmentManager
        
                    if (fm != null) {
                        EventClickDailog.newInstance("Delete Event")
                            .show(fm, EventClickDailog.TAG)
                    }
        
                }
        
                imgClosedlg.setOnClickListener {
                    dialog?.dismiss()
                }
            }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search