Error customizing a menu using actionLayout

2

I was using to customize my menu items the actionLayout attribute but, the following error occurred:

Layoutmenu_item.xml:

<?xmlversion="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:focusable="true"
    android:paddingTop="4dip"
    android:paddingBottom="4dip"
    android:paddingLeft="8dip"
    android:paddingRight="8dip"
    android:textAppearance="@android:attr/textAppearanceMedium"
    style="@android:attr/actionButtonStyle"
    android:textSize="6pt"
    android:textColor="@android:color/white"/>   
    
asked by anonymous 20.10.2014 / 13:34

1 answer

4

I have been able to solve it after much pain and with the help of @Wakim:

xml configuration:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto" > 

    <item
        android:id="@+id/acaoAdicionar"
        android:actionLayout="@layout/menu_item"
        android:icon="@android:drawable/ic_menu_add"
        android:showAsAction="ifRoom|withText"
        android:title="@string/adicionar"

        />

</menu>

Code in activity:

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_tefone, menu);
        configureActionLayout(menu);
    }

public void configureActionLayout(Menu menu) {// Menu Customizado

        for (int i = 0, c = menu.size(); i < c; ++i) {

            MenuItem item = menu.getItem(i);
            TextView actionLayout = (TextView) item.getActionView();
            actionLayout.setText(item.getTitle());
            actionLayout.setCompoundDrawablesWithIntrinsicBounds(
                    item.getIcon(), null, null, null);
            actionLayout.setOnClickListener(this);
        }
    }
    
24.10.2014 / 04:02