android---TextView相关属性学习(跑马灯效果)

本文介绍如何在Android中实现跑马灯效果,并展示了如何改变TextView中的文本颜色及添加链接的方法。

跑马灯效果:

<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="all"
       
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
       
        android:text="您好,欢迎观看我的android手机移动开发之路,博客:http://www.cnblogs.com/WTFly  联系电话:18729876537"
        android:textColor="#0000FF"
        android:textSize="23px"/>

其中ellipsize:(省略)

android:ellipsize = "end"    省略号在结尾

android:ellipsize = "start"   省略号在开头

android:ellipsize = "middle"     省略号在中间

android:ellipsize = "marquee"  跑马灯

focusableInTouchMode:获取焦点的方式focusable:设置是否获得焦点 

一个是设置焦点联系方式 一个是设置是否获得焦点。若有requestFocus()被调用时,后者优先处理

marqueeRepeatLimit:设置走马灯滚动的次数

singleLine= "true"  (跑马)确保是单行

 

改变文本颜色

 

方法一:整体改变:布局中

 

android:textColor="#FF0000"

 

方法二:代码设置:

 

     super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        TextView tView=new TextView(this);
        tView.setText(Html.fromHtml("欢迎来到<font color=red>www.cnblog.com/WTFly</font>;敬请关注!!!"));
        setContentView(tView);

 

方法三:自定义分段设置颜色 SpannableStringBuilder

TextView tView = new TextView(this);

String string ="Android开发测试"

 

 SpannableStringBuilder stringBuilder = new  SpannableStringBuilder(string);
 stringBuilder.setSpan(new ForegroundColorSpan(Color.RED), 0, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 stringBuilder.setSpan(new ForegroundColorSpan(Color.BLUE), 23, 58, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 stringBuilder.setSpan(new ForegroundColorSpan(Color.YELLOW), 58, 73, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 tView.setText(stringBuilder);

setContentView(tView);

 

添加链接

android:autoLink="all"

"all"  加上所有链接

"web"  网址链接

"email"  电子邮件链接

"phone"  电话链接

"map" 设置 android:autoLink="map"后需要有google地图才可以 否则会报错

"none" 不加链接

 

转载于:https://www.cnblogs.com/WTFly/p/3388746.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值