Force menu display in the action bar of cell phones with menu button

2

On Samsung-type phones that have the menu button, the action bar menu on android is not displayed, would you like to know if you can force it to display?

My menu.xml 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"

    />

    
asked by anonymous 03.06.2015 / 16:49

1 answer

2

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

The showAsAction attribute, when used with the library , must be preceded by the name of the app. I see you're putting this attribute in the namespace declaration of the application, I confess I do not know what the purpose is.

The way I use to 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 must be built in the onCreateOptionsMenu() method:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

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

Note: documentation can also be read it is not recommended to use "always" because it can cause problems on narrow screen devices. It is best to use "ifRoom" or "ifRoom|withText"

    
04.06.2015 / 23:48