Error when customizing a menu using actionLayout

Asked

Viewed 227 times

2

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

inserir a descrição da imagem aqui

Layout menu_item.xml:

<?xml version="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"/>   
  • 1

    Isn’t it working? Yours Activity inherits from Actionbaractivity`.

  • My activit inherits from Activity... I tried to inherit from Actionbaractivity but am not succeeding..

  • 1

    Is using the appcompat? The ActionBarActivity is from the library of app compat.

  • I could import but of the error.. I am using in my Activity tabs to be able to select the Ragments this can give error? because when I was inheriting from Activity there was no error, just no menu...

  • i already found the bug.. was on android:actionLayout="@layout/menu_item" can’t use a menucustomized

  • Yes, just add an equal attribute without the prefix android:.

  • i added the item with app:actionLayout="@layout/menu_item" but the xml error does not compile

  • It makes no sense, which error it generates?

  • I’ll take a print for you to see... I’ve looked in many forums and I didn’t see logic for this mistake.^^

  • 2

    @Pedrorangel noticed that you edited all your previous question to another. Since this is a new question, the ideal would be for you to create a new one and not edit this one, since the previous question may be doubt from other users, besides the comments here have been out of context with this edition.

  • @Paulorodrigues e pq when I asked a question, accidentally I put to grant reward... and had already solved... since it is not possible to return the points, I did not want to lose them and I asked another question^^

  • 1

    Pedro, I think you don’t miss when the time expires, it would be nice to see in the FAQ the rule. But as @Paulorodrigues said, it’s best to create a new question, because everything that was written before has lost its meaning.

  • blz...@Wakim and @Paulorodrigues thanks for the tip from you guys, sorry anything^^

Show 8 more comments

1 answer

4


I’ve managed to solve it after a lot of 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 on the 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);
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.