Closed tiansan closed 3 years ago
代码: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 }
服务协议颜色异常,隐私政策颜色正常。
您好,DialogX内部仅进行了AppCompatTextView#setText方法,请自行检查代码逻辑。
AppCompatTextView#setText
具体请参考:BaseDialog.java:348
代码: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 }