0

I have build a snackbar using the code below:

     // create text and icon
     val builderTextLeft = SpannableStringBuilder()
     builderTextLeft.append("   $message")
     builderTextLeft.setSpan(ImageSpan(context, R.drawable.ic_alertcircle), 0, 1, 0)
     builderTextLeft.setSpan(
         AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0,
         builderTextLeft.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
     )


     //setup snackbar
     val snackBarView: Snackbar =
         Snackbar.make(contextView, builderTextLeft, Snackbar.LENGTH_LONG)
             .setBackgroundTint(context.getColor(R.color.denotive_red))
             .setTextColor(context.getColor(R.color.gainsboro_00))

     val view: View = snackBarView.view
     val params = view.layoutParams as FrameLayout.LayoutParams
     params.gravity = Gravity.TOP
     params.height = 300
     view.layoutParams = params
     view.background = ContextCompat.getDrawable(
         context,
         R.drawable.checkered_red_background
     ) // for custom background
     snackBarView.animationMode = BaseTransientBottomBar.ANIMATION_MODE_FADE
     snackBarView.show()

It works but I notice a misalignment between the text and icon as shown below:

enter image description here

An idea why and how to fix it?

Seb
  • 2,659
  • 3
  • 23
  • 52
  • does this solve your problem? https://stackoverflow.com/questions/25628258/align-text-around-imagespan-center-vertical – nulldroid Jun 29 '21 at 19:31

0 Answers0