android TextView 笔记

1.当用TextView来响应事件时,需要双点才能响应:

certificates_tv_rec_date_start.setKeyListener(null);
certificates_tv_rec_date_start.setOnClickListener(this);

即事情响应前添加----        
.setKeyListener(null);
 

2.textView添加删除线

public class HelloActivity extends Activity{
   private  TextView tv;
    @Override
    public voidonCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       
       tv=(TextView)findViewById(R.id.tvId);
       tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
    }
}

其实Paint中的很多属性都可以用,比如下划线等等,大家可以自己测试下

3.TexTview单行多行

android:singleLine 用于指定该文本框是否为单行模式,其属性值为true或false,为true表示该文本框不会换行,当文本框中的文本超过一行时,其超出的部分将被省略,同时在结尾处添加“…”

android:ellipsize="end"
android:singleLine="true"


设置行数

android:lines="3"

4.格式

android:autoLink 
用于指定是否将指定格式的文本转换为可单击的超级链接形式,其属性值有none、web、email、phone、map或all

5.跑马灯

XML实现跑马灯:

android:singleLine="true"     //只有单行才可能有跑马灯效果
android:ellipsize="marquee"    //跑马灯效果
android:marqueeRepeatLimit="marquee_forever"   //跑马灯重复次数        
android:focusable="true" //由于Activity中没有写任何方法,故此处让其获得焦点
android:focusableInTouchMode="true"

android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"

继承TextView实现跑马灯

<TextView
        android:id="@+id/marquee"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:ellipsize="marquee"
        android:focusable="true"
        android:layout_gravity="top"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="#ff0000"
        android:textSize="20dp" />

跑马灯封装

package com.syh.app.zsg.entity;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class MarqueeText extends TextView {
public MarqueeText(Context con) {
 super(con);
}
public MarqueeText(Context context, AttributeSet attrs) {
 super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
// TODO Auto-generated method stub
// super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
引用
<com.syh.app.zsg.entity.MarqueeText
                        android:id="@+id/wjl_weath_11"
                        android:layout_marginTop="5dp"
                        android:text="晴  3/13 周四"
                        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:layout_gravity="top"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true" />

6.属性

在xml文件中使用android:textStyle=”bold” 可以将英文设置成粗体,但是不能将中文设置成粗体。
 将中文设置成粗体的方法是:

<pre name="code" class="java">TextView tv = (TextView)findViewById(R.id.TextView01); 
 TextPaint tp = tv.getPaint(); 
 tp.setFakeBoldText(true); 

 

7.部分文字设置颜色

TextView tView1=(TextView) findViewById(R.id.tv3); //找到tv3组件
tView1.setText(Html.fromHtml("大家好<font color=red>改变局部颜色</font>!")); //使用HTML标记设置文本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值