Android UI中TextView的使用方法

一、TextView不同區(qū)域設(shè)置顏色,大小、點(diǎn)擊事件
String msg = getResources().getString(R.string.school_roll_auth);
SpannableStringBuilder style = new SpannableStringBuilder(msg);
// 設(shè)置字體顏色
style.setSpan(
new ForegroundColorSpan(getResources().getColor(
R.color.tv_color_99)), 0, msg.length() - 5,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
style.setSpan(
new ForegroundColorSpan(getResources().getColor(
R.color.text_blue)), msg.length() - 5, msg.length(),
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
// 設(shè)置字體背景色
style.setSpan(
new BackgroundColorSpan(getResources().getColor(
R.color.bg_common)), msg.length() - 5, msg.length(),
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
// 設(shè)置可點(diǎn)擊部分
style.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
//do Click ....
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.clearShadowLayer();
}
}, msg.length() - 5, msg.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
tv_school_roll_msg.setText(style);
// 此方法在需要響應(yīng)用戶事件時(shí)使用,如點(diǎn)擊一個(gè)電話號(hào)碼就跳轉(zhuǎn)到撥號(hào)頁(yè)面。如果不執(zhí)行這個(gè)方法是不會(huì)響應(yīng)事件的,即便文本看著已經(jīng)是下劃線藍(lán)色字了。
tv_school_roll_msg.setMovementMethod(LinkMovementMethod.getInstance());
當(dāng)前標(biāo)題:AndroidUI中TextView的使用方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)于:http://www.chinadenli.net/article4/dcpiie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、移動(dòng)網(wǎng)站建設(shè)、虛擬主機(jī)、網(wǎng)站營(yíng)銷、網(wǎng)站設(shè)計(jì)公司、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容