2013-04-02 40 views
6

Tôi đã thêm một mục (có biểu tượng và văn bản) vào menu của ứng dụng.Tắt màu tô sáng của mục menu trong android

Tôi có hai hình ảnh cho trạng thái bình thường (không nén) của mục và cho trạng thái được nhấn mạnh (được nhấn).

Đây là trình đơn của tôi xml

<?xml version="1.0" encoding="utf-8"?> 

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:showAsAction="ifRoom|withText" 
     android:title="New" 
     android:icon="@drawable/menu_selector" 
     android:id="@+id/add_channel"></item>- 
</menu> 

Và đây là bộ chọn menu_selector.xml

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

    <item android:state_pressed="true" 
      android:drawable="@drawable/book"/> 

    <item android:state_selected="true" 
      android:state_pressed="false" 
      android:drawable="@drawable/book" /> 
</selector> 

Nhưng điều này là không đủ đối với tôi. Khi tôi nhấn mục, nó sẽ thay đổi hình ảnh mà nó chứa nhưng cũng có hiệu ứng ánh sáng màu xanh lá cây nổi bật trong nền.

Làm cách nào để vô hiệu hóa hoặc vô hiệu hóa hiệu ứng ánh sáng này?

+0

thể trùng lặp của [Làm thế nào thế nào để loại bỏ ánh sáng màu xanh từ mục trình đơn thanh tác vụ Sherlock?] (http://stackoverflow.com/questions/15705878/how-to-remove-blue-glow-from-sherlock-action-bar-menu-item) – guness

+0

có thể trùng lặp trong số [Xóa hiệu ứng ép trên biểu tượng biểu tượng trên thanh tác vụ] (http://stackoverflow.com/questions/23369749/remove-pressed-effect-on-action-bar-home-icon) – Fllo

Trả lời

2

Bạn có thể tạo bố cục bằng ImageButton và bộ chọn cho nền của nó để thay đổi màu trạng thái được nhấn. Chọn cách bố trí này tại đơn hàng của bạn: android:actionLayout="@layout/item_layout"

item_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/tab_button" 
     android:src="@drawable/ic_menu_item_icon" /> 

</LinearLayout> 

tab_button.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item 
    android:state_enabled="false" 
    android:drawable="@drawable/tab_button_background"/> 
<item 
    android:state_pressed="true" 
    android:state_enabled="true" 
    android:drawable="@drawable/tab_button_background_pressed" /> 
<item 
    android:state_focused="true" 
    android:state_enabled="true" 
    android:drawable="@drawable/tab_button_background" 
    /> 
<item 
    android:state_enabled="true" 
    android:drawable="@drawable/tab_button_background" 
    /> 
</selector> 

tab_button_background.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid 
     android:color="#9ec03b" /> 
</shape> 

tab_button_background_pressed.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid 
     android:color="#dfff53" /> 
</shape> 

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:id="@+id/add_channel" 
     android:showAsAction="ifRoom|withText" 
     android:actionLayout="@layout/item_layout" 
     android:title="New"> 
    </item> 
</menu> 
0

Nếu bạn có một người biết lắng nghe nhấp chuột vào mục bạn có thể đặt mã này trong xử lý:

menuItem.setChecked(false); 
Các vấn đề liên quan