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

Dialog内容使用SpannableString时,颜色会异常 #96

Closed tiansan closed 3 years ago

tiansan commented 3 years ago

微信截图_20210816165009

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

代码:2、 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 }

tiansan commented 3 years ago

服务协议颜色异常,隐私政策颜色正常。

kongzue commented 3 years ago

您好,DialogX内部仅进行了AppCompatTextView#setText方法,请自行检查代码逻辑。

kongzue commented 3 years ago

具体请参考:BaseDialog.java:348