Android之TextView

TextView是android最基本的view之一,其有许多常用的用法:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"    //设置整个TextView与其他组件的间距
        android:background="#0000ff"    //设置整个TextView的背景颜色
        android:padding="20dp"          //设置TextView中文字与边框的距离
        android:text="15395380870" 
        android:textColor="#ff0000"     //设置文字的颜色
        android:textSize="20dp"         
        android:typeface="serif"        //设置字体
        android:autoLink="phone" />     //设置自动链接到phone、email等应用

     <TextView
         android:id="@+id/mtv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#0000ff"
        android:padding="20dp"
        android:text="@string/myweb"     //设置链接到个人网页,在Java代码总也要设置
        android:textColor="#ff0000"
        android:textSize="20dp"
        android:typeface="serif"
         />
     
    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#0000ff"
        android:ellipsize="end"        //设置文字超出限制时的处理策略
        android:padding="20dp"
        android:singleLine="true"      //设置文字单行显示
        android:text="thisdfsdfsdfdsfdsfsdhfjhsjdisdfadfdftestsfkdhksdfkds!"
        android:textColor="#ff0000"
        android:shadowColor="#00ff00"   //设置文字阴影的颜色
        android:shadowDx="1"            //设置文字阴影的x方向上的偏移
        android:shadowDy="0"            //设置文字阴影的Y方向上的偏移
        android:shadowRadius="2"        //设置文字阴影半径
        android:textSize="20dp"
        android:typeface="serif" />

    <TextView
        android:id="@+id/tv"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#0000ff"
        android:ellipsize="marquee"          //设置跑马灯效果,要配合Java代码
        android:focusable="true"             //设置可得到焦点
        android:focusableInTouchMode="true"  //设置点击可得到焦点
        android:marqueeRepeatLimit="marquee_forever" //设置跑马灯效果策略
        android:padding="20dp"
        android:singleLine="true"
        android:text="thisdfsdfsdfdsfdsfsdhfjhsjdisdfadfdftestsfkdhksdfkds!"
        android:textColor="#ff0000"
        android:textSize="20dp"
        android:typeface="serif" />

    <Button 
        android:id="@+id/btn"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="test"
        android:focusableInTouchMode="true"/>

     <EditText 
        android:id="@+id/et"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="test"
        android:focusableInTouchMode="true"/>
    
</LinearLayout>

部分Java代码

      TextView tv = (TextView) findViewById(R.id.tv);
      tv.requestFocusFromTouch();//设置跑马灯
      TextView mtv = (TextView) findViewById(R.id.mtv);
      mtv.setMovementMethod(LinkMovementMethod.getInstance());//设置个人网页

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值