Force menu display in mobile phone action bar with menu button

Asked

Viewed 709 times

2

On phones type those of Samsung that has the menu button, the menu of the action bar on android is not displayed, I wonder if have to force the display of it?

My.xml menu looks like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:showAsAction="always"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item
    android:id="@+id/action_criar_conta"
    android:title="@string/action_criar_conta"
  />
<item
    android:id="@+id/action_entrar"
    android:title="@string/action_entrar"

    />
<item
    android:id="@+id/action_anuncie"
    android:title="@string/action_anunciar"

    />

1 answer

2

I suppose you must be wearing the v7 appcompat library and Theme.AppCompat.Light.DarkActionBar as Theme of the application.

The attribute showAsAction, when used with the library, has to be preceded by the app name.
I see you’re putting that attribute in the namespace application, I confess that I do not know what is the purpose.

The way I declare the menu is described in documentation:

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

    <item
        android:id="@+id/action_criar_conta"
        android:title="@string/action_criar_conta"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_entrar"
        android:title="@string/action_entrar"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_anuncie"
        android:title="@string/action_anunciar"
        app:showAsAction="always"/>

</menu>

In addition the menu should be built in the method onCreateOptionsMenu():

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
 }

Note: In the documentation can also read that it is not recommended to use "always" because it can cause "problems" of layout on "narrow screen" devices. In its replacement it is better to use "ifRoom" or "ifRoom|withText"

  • And on all devices the menu appears? I had problems with devices like Galaxy and s5360b

  • The problems you had were with your code or with mine? No Galaxy y don’t know but in the Galaxy Gio GT S5660 works.

  • With my code, I’ll test yours.

Browser other questions tagged

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