Tôi đã xóa các mạng nội bộ và tìm thấy nhiều bài đăng về cách thay đổi màu của chế độ xem danh sách bằng cách sử dụng công cụ chọn danh sách. Tuy nhiên nó không có vẻ làm việc cho tôi. Vì vậy, câu hỏi của tôi sẽ là những gì tôi đang làm sai?Tùy chỉnh màu của ListView Android?
Khi tôi sử dụng các tệp bên dưới, tôi nhận được danh sách nơi tất cả hình nền của mục màu xanh lam ban đầu. (Tôi mong đợi màu trắng)
Khi tôi di chuyển tiêu điểm lên và xuống, văn bản chỉ thay đổi thành màu xám đậm và hình nền vẫn có màu xanh dương. (Đây là khi tôi mong đợi một hàng duy nhất có màu xanh dương với phần còn lại màu trắng)
Khi tôi nhấp vào hàng, nền của hàng tôi nhấp vào chuyển sang màu đen và tất cả các hàng khác chuyển sang màu xanh lục. (Tôi dự kiến sẽ có hàng tôi nhấp chuyển sang màu xanh và phần còn lại có màu trắng)
Đây là chính bố trí tập tin của tôi:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:listSelector="@drawable/item_selector"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty"
/>
</LinearLayout>
Dưới đây là danh sách tập tin mục của tôi:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10sp">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textStyle="bold"
android:padding="7dip"
android:textSize="18sp"
android:layout_toRightOf="@id/checkbox"
/>
</RelativeLayout>
đây là tập tin màu của tôi:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#ff00</color>
<color name="green">#f0f0</color>
<color name="blue">#f00f</color>
<color name="white">#ffff</color>
</resources>
Đây là tập tin chọn của tôi:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:drawable="@color/blue" />
<item
android:drawable="@color/white" />
</selector>
Hy vọng đó là điều ngu ngốc và đơn giản mà tôi đang làm sai.
Xin cảm ơn trước.
có vẻ như toàn bộ danh sáchXem chính nó đang được tập trung thay vì các mục danh sách riêng lẻ. – YGL