溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android 給TextView的內(nèi)容 添加跳轉(zhuǎn)無下劃線

發(fā)布時間:2020-07-18 01:17:26 來源:網(wǎng)絡(luò) 閱讀:504 作者:douruanliang 欄目:移動開發(fā)
     String url = data.blockChainUrl;        //https or http url
     SpannableStringBuilder builder = new SpannableStringBuilder("");
            int start = builder.length();
            String content = mContext.getResources().getString(R.string.block_chain_query); //填充字體顏色
            builder.append(content);
            int end = builder.length();

            builder.setSpan(new URLSpanNoUnderline(url) {
                @Override
                public void onClick(View widget) {
                    super.onClick(widget);
                }
            }, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.color_a5ef44)), 0,
                    end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            mBlockChainQuery.setText(builder);
           //必須有的set mBlockChainQuery.setMovementMethod(LinkMovementMethod.getInstance());

//自定義一個URLSpan

class URLSpanNoUnderline extends URLSpan {
        public URLSpanNoUnderline(String url) {
            super(url);
        }
       @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
                        //you  self
        }
    }
向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI