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:
An idea why and how to fix it?