Pergunta

I would like to add two buttons into the action bar, but in my case just one button appears. What is wrong with my code?

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:myApp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:icon="@drawable/ic_action_settings"
      myApp:showAsAction="ifRoom"/>

<item android:id="@+id/action_about"
    android:title="@string/action_about"
    android:icon="@drawable/ic_action_about"
    myApp:showAsAction="ifRoom"/> 
</menu>
Foi útil?

Solução

like this use always instead of ifRoom

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:icon="@drawable/ic_action_settings"
      myapp:showAsAction="always"/>

<item android:id="@+id/action_about"
    android:title="@string/action_about"
    android:icon="@drawable/ic_action_about"
    myapp:showAsAction="always"/> 
</menu>

Read documentation

You can also use "always" to declare that an item always appear as an action button. However, you should not force an item to appear in the action bar this way. Doing so can create layout problems on devices with a narrow screen. It's best to instead use "ifRoom" to request that an item appear in the action bar, but allow the system to move it into the overflow when there's not enough room. However, it might be necessary to use this value if the item includes an action view that cannot be collapsed and must always be visible to provide access to a critical feature.

Reference

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top