zoukankan      html  css  js  c++  java
  • 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" 不加链接

  • 相关阅读:
    Day15模块(导入,使用)
    day14 迭代器,生成器,函数的递归调用
    Day13有参装饰器,三元表达式,匿名函数
    re模块
    Day12装饰器
    subprocess模块windows系统命令和linux系统命令
    Day11名称空间,作用域,闭包函数
    识别 Linux上的设备(磁盘)类型
    Linux lsblk和df命令区别
    Linux远程拷贝scp
  • 原文地址:https://www.cnblogs.com/WTFly/p/3388746.html
Copyright © 2011-2022 走看看