Q1) Nhìn vào gốc drawable ListView
nhà nước cho listSelector
chúng tôi có một cái gì đó như thế này (tôi bị tước một số mã để đơn giản hóa ví dụ):Bất kỳ sự khác biệt về hành vi nào từ các bản vẽ trạng thái hơi khác nhau này?
<selector>
<item android:drawable="<TRANSPARENT>" android:state_window_focused="false"/>
<item android:drawable="<DRAWABLE_1>" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="<DRAWABLE_1>" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="<DRAWABLE_2>" android:state_focused="true"/>
</selector>
Nhưng tôi đã làm nó như thế này trên ứng dụng của tôi:
<selector>
<item android:drawable="<DRAWABLE_2>" android:state_pressed="false" android:state_focused="true"/>
<item android:drawable="<DRAWABLE_1>" android:state_pressed="true"/>
<item android:drawable="<TRANSPARENT>" />
</selector>
Điều này dường như tạo ra kết quả tương tự và đơn giản hơn nhiều. Bạn có nhận thấy bất kỳ tình huống nào trong đó trường hợp đầu tiên sẽ hoạt động tốt hơn phiên bản của riêng tôi? Tôi chỉ muốn chắc chắn rằng tôi không bỏ lỡ điều gì đó quan trọng vì tôi muốn giữ mã của mình càng ngắn càng tốt ...
Q2) Tôi thấy nhiều trạng thái có thể rút được với <item android:drawable="<TRANSPARENT>" android:state_window_focused="false"/>
làm mặt hàng đầu nhưng tôi có thể ' t hiểu tại sao nó lại cần thiết. state_window_focused
luôn làm tôi bối rối ... Có thực sự cần thiết không?