2012-01-26 28 views
23

Tôi đang cố thay đổi màu của hiệu ứng rollover khi bạn chạm vào một mục ActionBar. Trên Galaxy Nexus của tôi với 4.0.2, đó là loại màu xanh ngọc mà tôi muốn có màu khác.Làm cách nào để thay đổi màu hiệu ứng cảm ứng của ActionBar trong Android 3.0 và cao hơn

Để rõ ràng, tôi đang nói về các mục ActionBar ở đây, không phải tab điều hướng.

Tôi làm cho nó hoạt động trong thư viện tương thích, nhưng đối với Android 3.0 trở lên, tức là ActionBar "thực", tôi không thể tìm ra cách thực hiện điều này.

Có ai biết nếu và làm thế nào điều này có thể đạt được?

Trả lời

45

Thanh tác vụ gốc sử dụng thuộc tính chủ đề selectableItemBackground cho bản vẽ nền của mục tác vụ. Đây phải là danh sách nhà nước có thể vẽ được.

Đây là tuyên bố trong Theme.Holo:

<style name="Theme.Holo"> 
    <!-- bunch of things --> 
    <item name="android:selectableItemBackground">@android:drawable/item_background_holo_dark</item> 
    <!-- bunch of things --> 
</style> 

Và XML drawable của nó:

<selector xmlns:android="http://schemas.android.com/apk/res/android" 
      android:exitFadeDuration="@android:integer/config_mediumAnimTime"> 

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --> 
    <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_dark" /> 
    <item android:state_focused="true" android:state_enabled="false"        android:drawable="@drawable/list_selector_disabled_holo_dark" /> 
    <item android:state_focused="true"        android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" /> 
    <item android:state_focused="false"        android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" /> 
    <item android:state_focused="true"                android:drawable="@drawable/list_focused_holo" /> 
    <item                       android:drawable="@color/transparent" /> 
</selector> 
+0

Cảm ơn phản hồi nhanh chóng của bạn. Nhưng nếu tôi cố gắng ghi đè thuộc tính này theo kiểu như Tôi gặp lỗi: Không tìm thấy tài nguyên nào khớp với tên đã cho: attr 'selectableItemBackground'. Tôi có thể ghi đè thuộc tính này ở đâu hoặc ở đâu? – Alf

+0

Xin lỗi, bạn sẽ phải sử dụng 'name =" android: selectableItemBackground "'. Nó không được chỉ định trong phiên bản nền tảng Android của chủ đề vì gói mặc định của nó đã là 'android'. Tôi đã cập nhật câu trả lời. –

+0

Hoạt động hoàn hảo, cảm ơn bạn rất nhiều! – Alf

Các vấn đề liên quan