目錄:android.widget.TextView
設置顏色:
方式一:
tv_textView.setTextColor(getResources().getColor(R.color.colorAccent));
方式二:
tv_textView.setTextColor(Color.parseColor("#FDFF00"));
方式三:
tv_textView.setTextColor(Color.rgb(93, 95, 98));
方式四:
tv_textView.setTextColor(0xffff0000);
(還有知道其他設置的方式,可以留言,后面補充)
設置加粗:
方式一:控件使用屬性
android:textStyle="bold"
方式二:通過TextView的Paint對象設置
TextView tv = (TextView)findViewById(R.id.tv);
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);
設置字體陰影:
- android:shadowColor:陰影的顏色
- android:shadowDx:水平方向上的偏移量
- android:shadowDy:垂直方向上的偏移量
- Android:shadowRadius:是陰影的的半徑大少
補充:最好這4個值都一起設計
實現文本跑馬燈效果:
步驟一,單行文本:(推薦使用android:maxLines="1"屬性代替)
android:singleLine="true"
步驟二,滾屏屬性:
android:ellipsize="marquee"
補充:marquee (滾屏),start(省略號在開頭),middle(省略號在中間),end(省略號在結尾)
步驟三,設置聚焦:
android:focusable="true"
android:focusableInTouchMode="true"
步驟四,設置滾動的循環次數,無限:marquee_forever或-1,其余的直接寫數字即可
android:marqueeRepeatLimit="marquee_forever"
設置全文、收起效果:
//默認初始化顯示和狀態
tv_publishContent.post(new Runnable() {
@Override
public void run() {
int lineCount = tv_publishContent.getLineCount();
L.i("lineCount:" + lineCount);
if(lineCount>5){//初始化狀態
tv_show_more.setVisibility(View.VISIBLE);
tv_show_more.setText("全文");
isShowMore = true;
}else{
tv_show_more.setVisibility(View.GONE);
isShowMore = false;
}
}
});
//通過狀態處理點擊事件是全文還是收起
tv_show_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isShowMore){
isShowMore = false;
tv_show_more.setText("收起");
tv_publishContent.setMaxLines(Integer.MAX_VALUE);
}else{
isShowMore = true;
tv_show_more.setText("全文");
tv_publishContent.setMaxLines(5);
}
}
});