selector如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:state_selected="true" android:color="@color/calendar_text_selected"/> <item android:state_pressed="true" android:color="@color/calendar_text_selected"/> <item android:color="@color/white" android:state_checked="true"/> <item android:color="@color/black24"/> </selector>
之后如果在XML中将这个selector设置给textView的textColor(不要忘了加上clickable=true或者设置onClick事件),然后使用我们会发现textView还是只响应了pressed状态,
而没有响应selected,这是因为selected状态需要我们在代码中设置,具体代码:tv.setSelected(boolean),imageView与button同理