vendredi 8 mai 2015

Custom Layout menu item shows empty if showAsAction=never

I am trying to add SwitchCompat to Overflow menu using this code below:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://ift.tt/nIICcg"
   xmlns:app="http://ift.tt/GEGVYd">
    <item
       android:id="@+id/menu_dummy_content"
       android:title=""
       android:actionViewClass="android.support.v7.widget.SwitchCompat"
       app:showAsAction="never"
       app:actionLayout="@layout/menu_item_switch"/>

    <!-- TODO: Delete this after bug fix-->
    <item
       android:id="@+id/menu_dummy_content_2"
       android:title="Second Title"
       app:showAsAction="never"/>
</menu>

The layout for menu_item_switch is:

<android.support.v7.widget.SwitchCompat
    xmlns:android="http://ift.tt/nIICcg"

    android:id="@+id/menu_item_switch_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="@string/menu_item_dummy_tasks"
    android:layout_centerVertical="true"/>

If I do app:showAsAction="ifRoom" or anything, the switch appears perfectly fine and the listeners work fine. But as soon as I make the showAsAction as never. The switch view becomes white/empty but the onOptionsItemSelected says the clicked item is menu_dummy_content.

I also tried using only TextView in the custom layout, and that too comes as empty. Am I missing something?

Aucun commentaire:

Enregistrer un commentaire