【发布时间】:2021-11-25 04:07:12
【问题描述】:
所以我添加了一个快餐栏来通知用户成功或失败...但是文本和图标没有正确对齐,我不知道如何正确地做到这一点
fun notifyUserMessage(context: Context, contextView: View, message: String,
notificationType: NotificationTypes = NotificationTypes.ERROR){
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
)
val snackbar = Snackbar.make(contextView, builderTextLeft, Snackbar.LENGTH_LONG)
.setBackgroundTint(context.getColor(setBackground(notificationType)))
.setTextColor(context.getColor(R.color.gainsboro_00))
val params = snackbar.view.layoutParams as FrameLayout.LayoutParams
params.gravity = Gravity.TOP
params.height = 250
snackbar.animationMode = BaseTransientBottomBar.ANIMATION_MODE_FADE
snackbar.show()
}
但结果看起来像:
我希望文本与图标正确对齐,但还要确保“文本+图标”都在小吃栏中居中。
有什么想法吗?
【问题讨论】:
标签: android kotlin android-notifications android-snackbar