6

アプリケーションのメニューにアイテム (アイコンとテキスト付き) を追加しました。

アイテムの通常の (押されていない) 状態と強調表示された (押された) 状態の 2 つの画像があります。

これは私のメニュー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>

そして、これはセレクタ 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>

しかし、これは私にとって十分ではありません。アイテムを押すと、含まれている画像が変更されますが、背景に緑色のグロー効果がハイライトされます.

このグロー効果を無効にする、または非表示にするにはどうすればよいですか?

4

2 に答える 2

2

ImageButton とその背景のセレクターを使用してレイアウトを作成し、押された状態の色を変更できます。あなたのアイテムのメニューでこのレイアウトを選択してください: 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>
于 2013-04-02T21:23:00.360 に答える
0

項目にクリック リスナーがある場合は、次のコードをハンドラーに配置できます。

menuItem.setChecked(false);
于 2016-04-10T00:53:26.487 に答える