SpannableString修改颜色、下划线、下划线点击事件、清空自带背景


        SpannableString spannableString = new SpannableString(toastMessageTxt);
        spannableString.setSpan(new UnderlineSpan(), underLineStart, underLineEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(@NonNull View widget) {
                // 拨打电话 提示弹窗
                showCustomerServicePhone();
            }
        }, underLineStart, underLineEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.skin1)), underLineStart,
                underLineEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置透明背景
        toastText.setHighlightColor(Color.parseColor("#00FFFFFF"));
        toastText.setMovementMethod(LinkMovementMethod.getInstance());
        toastText.setText(spannableString);

你可能感兴趣的:(资料)