2013-04-02 14 views
6

Uygulamamın menüsüne bir öğeyi (simge ve metin içeren) ekledim.Android'de menü öğesinin arka plan vurgu rengini devre dışı bırak

Öğenin normal (baskılanmamış) durumu ve vurgulanan (basılı) durum için iki resmim var.

Bu benim menü 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> 

Ve bu selektör 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> 

olduğunu Ama bu benim için yeterli değildir. Öğeye bastığımda, içerdiği görüntüyü değiştirir, ancak arka planda yeşil bir parlama efekti de vurgulanır.

Bu ışıma efektini nasıl devre dışı bırakabilirim veya görünmez hale getirebilirim?

+0

olası yinelenen [Nasıl Sherlock eylem çubuğu menü öğesinden mavi parlaklığı kaldırmak için?] (http://stackoverflow.com/questions/15705878/how-to-remove-blue-glow-from-sherlock-action-bar-menu-item) – guness

+0

olası yineleme [Kaldır eylem çubuğu ev simgesine basılmış efekt] (http://stackoverflow.com/questions/23369749/remove-pressed-effect-on-action-bar-home-icon) – Fllo

cevap

2

Basılan durum rengini değiştirmek için bir ImageButton ile bir düzen ve arka planı için bir seçici oluşturabilirsiniz. menü öğeyi bu düzen seçin : 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

Eğer işleyicisi Bu kodu koyabilirsiniz öğe üzerinde bir tıklama işleyicisi varsa: ait

menuItem.setChecked(false); 
İlgili konular