Hi các bạn,
Hiện tại mình muốn thực hiện chức năng như sau:
Khi click vào item trong listview, thì selector của item thay đổi, đồng thời text color cũng thay đổi theo ý muốn
giống như các trạng thái trong selector ( pressed, focus, visible,...) . Ở đây là mình đang custom 1 listview, item listview có 1
TextView.
Bạn nào đã làm kiểu này hay là biết cơ chế thực thi thì giúp mình với. Nếu có cách nào mà chỉ set selector mà không cần phải
thực thi coding thì càng tốt.
Thanks!
- - - Nội dung đã được cập nhật ngày 30-11-2015 lúc 10:10 AM - - -
Done!
Mình thiết lập selector cho ListView và text color cho TextView mà muốn đổi màu khi click vào item trong ListView.
Demo:
list_selector.xml ( đặt trong res/drawable)
Mã:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white"
android:state_focused="false"/>
<item android:drawable="@android:color/holo_blue_bright" android:state_enabled="false"
android:state_focused="true"
android:state_pressed="true"/>
<item android:drawable="@android:color/holo_blue_bright" android:state_enabled="false"
android:state_focused="true"/>
<item android:drawable="@android:color/holo_green_dark" android:state_focused="true"
android:state_pressed="true"/>
<item android:drawable="@android:color/holo_green_dark" android:state_focused="false"
android:state_pressed="true"/>
<item android:drawable="@android:color/holo_purple"
android:state_focused="true"/>
</selector>
textcolor.xml ( đặt trong res/color)
Mã:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/holo_green_light" android:state_selected="true"/>
<item android:color="@android:color/black" android:state_focused="true"/>
<item android:color="@android:color/holo_blue_bright" android:state_pressed="true"/>
<item android:color="@android:color/black"/>
</selector>
View more random threads:
Dưới ánh nắng mặt trời đang lên, những đống pallet nhựa An Giang trải dài mênh mông như những bức tranh tự nhiên đầy sắc màu. Mỗi chiếc pallet nhựa không chỉ là một vật dụng thông thường mà còn là...
Pallet nhựa An Giang giao hàng...