textView相关知识
来源:互联网 发布:mastercam三维编程步骤 编辑:程序博客网 时间:2024/06/11 18:37
一、给textview设置颜色为#fffff
有时候我们会从服务器获得数据,但是后台给的服务器的值是比如:#B373FB
此时要想给TextView设置文字直接设置textview.setTextColor();是不行的。此时我们可以这样
String str = floorcolor;int id = Color.parseColor(str);//#ffffff设置成color对象tv_select1.setTextColor(id);
tv_select1为TextView,floorcolor比如:"#ffffff"
二、TextView的跑马灯效果,这个很简单
为了解决TextView不会在失去焦点的时候不滚动的问题,我自定义一个TextView,重写isFocused方法设置为true
public class MarqueeTextView extends TextView { public MarqueeTextView(Context context) { super(context); } public MarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; }}跑马灯布局如下
<com.spark.huabang.view.MarqueeTextView android:id="@+id/get_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="35dp" android:layout_marginLeft="10dp" android:ellipsize="marquee" android:focusable="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="中奖名单:" android:textColor="@android:color/white" android:textSize="16sp"></com.spark.huabang.view.MarqueeTextView>
三、现在跑马灯的TextView的数据,我假设有三段字符串构成:
Textview.setText(s);
s=s1+s2+s3;
此时,要想设置第二段字符串的颜色为红色,可以使用spannableStringBuilder的方法:
如果对首先用s+=s1;然后用
SpannableStringBuilder style = new SpannableStringBuilder(s);
style.setSpan(new ForegroundColorSpan(Color.RED), 0, s2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
最后使用s=s+s2+s3;TextView.setText(s);运行后会发现没反应,此时应该这么做才是正确的:
SpannableStringBuilder style = new SpannableStringBuilder(s);
style.setSpan(new ForegroundColorSpan(Color.RED), s.length()-s2.length,
s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView.setText(style);
此时就可以设置完成了
阅读全文
0 0
- Textview相关知识
- textView相关知识
- textview相关
- TextView相关
- TextView相关
- TextView相关
- TextView相关
- TextView相关
- 【TextView】Android TextView相关操作
- TextView杂知识
- 知识梳理:TextView
- Textview一些小知识
- TextView 相关属性
- textview显示相关
- Android TextView相关属性
- android TextView相关
- TextView相关属性
- TextView文本显示相关
- sql时间查询
- 数据结构----二叉树(交换子树)
- js面向对象编程:如何定义常量?
- java动态代理原理解析
- oracle存储函数
- textView相关知识
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(五)
- 有儿子之后
- 转载一篇MTK平台Camera(OV13850)驱动移植说明
- 第十三周-Java集合框架Map
- rpm的查看安装的应用以及查看mysql的安装状态
- pio中关于excel单元问题
- RN工程修改完依赖 即修改了package.json文件 如何重新安装依赖
- arcgis发布服务显示打包成功,发布失败,无法写入D:\arcgisserver\directories\arcgiscache