TextView控制項使用小技巧

2021-08-26 04:30:58 字數 943 閱讀 5535

一、設定字型顏色的三種方法

1、android:textcolor //直接設定整體文字顏色

2、利用html標記

textview tv= (textview)findviewbyid(r.id.tv);

tv.settext(html.fromhtml("時間厲害,逃得出黑洞,避不過輪迴。"));

3、自定義乙個style

spannablestringbuilder style=new spannablestringbuilder(str);

//下面括號裡面分別是(顏色,起始位置,結束位置,乙個常量)

style.setspan(new foregroundcolorspan(color.red), 0, 6, spannable.span_exclusive_exclusive);

style.setspan(new foregroundcolorspan(color.green), 6, 21, spannable.span_exclusive_exclusive);

style.setspan(new foregroundcolorspan(color.blue), 21, 34, spannable.span_exclusive_exclusive);

tv.settext(style);

二、跑馬燈效果:

android:singleline="true"

android:focusable="true"

android:ellipsize="marquee"

android:marqueerepeatlimit="marquee_forever"

android:focusableintouchmode="true"

TextView小技巧記錄下

忘了是看誰的部落格 大致寫法都差不多 spannablestring string new spannablestring item.getcontent verticalimagespan imagespan new verticalimagespan mcontext,r.drawable.ic...

TextView控制項

下面我們將比較一下android中的textview和c winform中textbox的不同。c textbox1 直接輸入控制項的名稱即可 android textview tv textview this.findviewbyid r.id.tv 獲取文字框控制項物件,有點像html中gete...

TextView控制項

下面我們將比較一下android中的textview和c winform中textbox的不同。c textbox1 直接輸入控制項的名稱即可 android textview tv textview this.findviewbyid r.id.tv 獲取文字框控制項物件,有點像html中gete...