Tapadoo / Alerter

An Android Alerting Library
MIT License
5.52k stars 633 forks source link

How to display alert above dialog? #209

Closed jaydeep2158 closed 4 years ago

kpmmmurphy commented 4 years ago

Hey @jaydeep2158, unfortunately this isn't supported. You'll either need to show the alert before, or after dismissing the dialog.

abhishektiwarijr commented 4 years ago

We can achieve that by doing so Step 1: Paste this method code in Alerter.kt class

fun show(dialogDecorView: ViewGroup?) { activityWeakReference?.get()?.let { it.runOnUiThread { //Add the new Alert to the View Hierarchy dialogDecorView?.addView(alert) } } }

Step 2: Now use the above show method as following code.

fun String.showToastAboveDialog(context: Activity, viewGroup: ViewGroup?) { if (this.isNotEmpty()) Alerter.create(context) .enableIconPulse(false) .setIcon(R.drawable.icon_error_red) .enableSwipeToDismiss() .setText(this) .show(viewGroup) }

Use above method as: "Hello".showToastAboveDialog( requireActivity(), referenceBinding.flRoot //parent view from dialog layout ) Note :

Parent view must have width and height match_parent Parent's immediate child must have android:layout_gravity="center" set dialog layout width and height to match_parent like below dialog.window?.setLayout( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT )

Now you're ready to go. I know it's a little bit weird but can't help it. (>_<) Enjoy!

CatchABus commented 4 years ago

Any progress on this one?