1

I have a snackbar but when switching activity's it stays on the original activity it had been activated. Is there a way to make it stay on screen when switching activity's?

    val mainSnackBar = Snackbar.make(findViewById(android.R.id.content), "", Snackbar.LENGTH_SHORT)
    val llp = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
    llp.topMargin = 20
    llp.bottomMargin = 20

           

This is the code when clicking on a button to switch activity's:

mainSnackBar.apply {
                setActionTextColor(Color.BLACK)
                view.setBackgroundColor(resources.getColor(R.color.good_color))
                setText("Snackbar Message")
                val snackTextView = view.findViewById(com.google.android.material.R.id.snackbar_text) as TextView
                snackTextView.textSize = 17f
                snackTextView.layoutParams = llp
                snackTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check, 0, 0, 0)
            }.show()
mohammed_sajid
  • 233
  • 2
  • 18
  • Does this answer your question? [Android Persist A SnackBar Across Activities](https://stackoverflow.com/questions/29989631/android-persist-a-snackbar-across-activities) – JustSightseeing Jun 15 '22 at 15:04
  • @JustSightseeing This post suggests I make a custom toast/snackbar file. However I would like to use the build in snackbar feature to keep it simple and optimized. – mohammed_sajid Jun 16 '22 at 07:47
  • ASAIK, this would not be possible, you would need to make a custom snackbar/toast to achieve that – JustSightseeing Jun 16 '22 at 14:13

0 Answers0