Closed tiansan closed 3 years ago
您是否有使用设置全局 textInfo,例如DialogX.messageTextInfo
它会对文字的样式、颜色产生影响。
解决方案为在 show() 方法后执行 setMessageTextInfo(null)
spanString.setSpan(colorSpan,7,13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spanString.setSpan(colorSpan,14,20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) 第一个异常第二个正常
没有设置全局的textinfo
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 }