2012-09-12 7 views
7

Tôi đang cố gắng thêm vào danh sách thống kê hiện tại có thể vẽ, trạng thái bị vô hiệu hóa và nó không hoạt động.Android có thể vẽ được statelist: state_enabled không hoạt động trong xml

ban đầu, tôi đã có mã này:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/> 
<item android:drawable="@drawable/store_item_background"/> 
</selector> 

và nó làm việc hoàn hảo cho lựa chọn và không được chọn.

bây giờ tôi muốn thêm android: state_enabled = "false" như thế này:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/> 
<item android:drawable="@drawable/store_item_background" android:state_enabled="true"/> 
<item android:drawable="@drawable/store_item_background_disabled"/> 
</selector> 

và nó không bao giờ chuyển sang hình ảnh người tàn tật.

bất kỳ ý tưởng nào?

EDIT

tôi thêm setEnabled(false) đến constructor của xem Tôi đang thiết statelist drwable này và bây giờ tôi nhìn thấy hình ảnh tàn tật, nhưng một khi tôi đặt chế độ xem để được kích hoạt, nó sẽ không chuyển sang khuyết tật lại .

Trả lời

7

Hãy thử điều này

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:drawable="@drawable/store_item_background_selected" android:state_enabled="true" android:state_selected="true"/> 
<item android:drawable="@drawable/store_item_background" android:state_enabled="true"/> 
<item android:drawable="@drawable/store_item_background_disabled" android:state_enabled="false"/> 

</selector> 
+0

không tạo sự khác biệt. xem chỉnh sửa – piojo

+0

xin lỗi, lỗi trong mã của tôi, nơi tôi đặt nó để vô hiệu hóa. – piojo

+0

câu trả lời không tốt. Không giải thích được NOR. – Vucko

15

Mặc dù đây là một câu hỏi thực sự cũ. Bật nên ghi bộ chọn phù hợp.

  1. khuyết tật tiểu bang đầu tiên
  2. ép trạng thái thứ hai
  3. trạng thái bình thường cuối cùng

+0

chuyển đơn đặt hàng ngay lập tức đã khắc phục được sự cố của tôi. bạn đã tìm thấy thông tin này ở đâu? –

+0

Một số nơi trên google khi tôi bị kẹt trong nhiều giờ trong cùng một vấn đề này –

+0

Tôi đã gặp sự cố này trong một thời gian dài bằng cách sử dụng phương pháp này: StateListDrawable res = new StateListDrawable(); res.addState (int mới [] {- ​​android.R.attr.state_enabled}, màu mới có thể vẽ màu (màu)); res.addState (new int [] {android.R.attr.state_enabled, android.R.attr.state_pressed}, mới ColorDrawable (màu)); res.addState (new int [] {}, màu mới có thể vẽ được (màu)); Và điều này làm việc ngay lập tức. Cảm ơn. muốn nó được ghi lại ở đâu đó ... – ClayHerendeen