Android中控件使用技巧之:TextView

1. 使用style+代码控制TextView的不同状态下的颜色(selected,pressed,normal)

 <LinearLayout
     android:id="@+id/linearLayout_tap1"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="180"
     android:background="@drawable/selector_lin_layout_left_tab"
     android:gravity="center"
     android:orientation="vertical" >

     <ImageButton
         android:id="@+id/img_btn_edit2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@android:color/transparent"
         android:clickable="false"
         android:src="@drawable/selector_img_btn_left_tab1" />

     <TextView
         android:id="@+id/textView_edit2"
         style="@style/textView_tap_left"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="移动" />
 </LinearLayout>

    <style name="textView_tap_left">
        <item name="android:textColor">@color/color_text_left_tab</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
    </style>


color_text_left_tab.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:color="#ffff0000"/>
    <item android:state_selected="true" android:color="#ff168fb9"/>
    <item android:color="#6c6c6c"/>

</selector>

父控件linearLayout_tap1被点击时候,设置TextView为Selected状态

TextView textView_edit2 = (TextView) findViewById(R.id.textView_edit2);
textView_edit2.setSelected(true);


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值