kongzue / DialogX

💬 DialogX dialog box component library, easy to use, more customizable, more scalable, easy to achieve a variety of dialog boxes. DialogX对话框组件库,更加方便易用,可自定义程度更高,扩展性更强,轻松实现各种对话框、菜单和提示效果,更有Material You、iOS、MIUI等主题扩展可选
Apache License 2.0
2.11k stars 222 forks source link

消息对话框使用SpannableString为消息内容时,颜色会异常 #90

Closed tiansan closed 3 years ago

tiansan commented 3 years ago

MessageDialog.build() .setTitle("温馨提示") .setMessage(getMessage()) .setOkButton("同意") .setCancelButton("暂不使用" ) { , -> PopTip.show("点击暂不使用按钮") false } .setOkButton { , -> PopTip.show("点击确定按钮") false } .show(this)

private fun getMessage(): CharSequence { val content = resources.getString(R.string.user_privacy2) val spanString = SpannableString(content) val colorSpan = ForegroundColorSpan(Color.parseColor("#0000ff")) val privacy: ClickableSpan = object : ClickableSpan() { override fun onClick(widget: View) { PopTip.show("隐私政策") } } val agreement: ClickableSpan = object : ClickableSpan() { override fun onClick(widget: View) { PopTip.show("服务协议") } } spanString.setSpan(agreement,7,13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spanString.setSpan(privacy,14,20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spanString.setSpan(colorSpan,7,13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spanString.setSpan(colorSpan,14,20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) return spanString }

kongzue commented 3 years ago

您是否有使用设置全局 textInfo,例如DialogX.messageTextInfo 它会对文字的样式、颜色产生影响。 解决方案为在 show() 方法后执行 setMessageTextInfo(null)

tiansan commented 3 years ago

spanString.setSpan(colorSpan,7,13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spanString.setSpan(colorSpan,14,20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) 第一个异常第二个正常

tiansan commented 3 years ago

没有设置全局的textinfo