目录: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);
}
}
});
网友评论