TextView没有按下状态,Button有。

如图1,内容1在一个TextView上,默认它并没有按下状态。

Drawable(7)让一个没有pressed状态的控件使用StateList,显示pressed图片。

如何让TextView有呢。

在xml中加入属性: android:clickable="true"  就可以作用StateList Drawable了。

Drawable(7)让一个没有pressed状态的控件使用StateList,显示pressed图片。

代码如:

 1 <TextView
 2         android:layout_width="wrap_content"
 3         android:layout_height="wrap_content"
 4         android:text="msg content"
 5         android:textAllCaps="false"
 6         android:background="@drawable/msgbg_state"
 7         android:id="@+id/msg_content"
 8         android:gravity="top|left"
 9         android:focusable="true"
10         android:clickable="true"
11         android:padding="15dp"
12         android:layout_gravity="center_vertical" />

msgbg_state.xml

1 <?xml version="1.0" encoding="utf-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android"
3     android:dither="false">
4 
5     <item android:state_pressed="true" android:drawable="@drawable/msglf" /> <!-- state_pressed -->
6     <item android:drawable="@drawable/msgl" /> <!-- default -->
7 </selector>

两个状态的.9图片如下:

Drawable(7)让一个没有pressed状态的控件使用StateList,显示pressed图片。    Drawable(7)让一个没有pressed状态的控件使用StateList,显示pressed图片。

 

相关文章:

  • 2021-12-16
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2021-12-03
  • 2022-12-23
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-11-26
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案