4
votes

I have an action bar with the follwing menu:

<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="br.com.putzbati2.PrincipalActivity" >
    <item android:id="@+id/action_mensagem"
        android:title="Mensagem"
        android:icon="@drawable/barra_superior_envelope"
        android:showAsAction="always|withText" />
    <item android:id="@+id/action_carro"
        android:icon="@drawable/barra_superior_carro"
        app:showAsAction="always"
        android:title="Meus Carros"/>
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />
</menu>

But the withText doesnt work. It shows only the icon. I've already try to use android:showAsAction instead of app:showAsAction and when I do this, it doesnt show the icon neither the text. Does any one know how to help me?

I've found this solution, but as I said, it doesnt work for me app:showAsAction ifRoom is not working on appcompat action bar

1
remove always keep it withText onlyNadir Belhaj

1 Answers

1
votes

You can use like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/action_mensagem"
          android:title="@string/id_item_mensagem"
          android:icon="@drawable/id_item_mensagem"
          android:showAsAction="always|withText" />
    <!-- ... another items -->
</menu>

'always|withText' will work if there is enough room, otherwise it will only place icon! You are using so much items with text, probably you don't have room. So you will see only the icon.

You can check it if you rotate your application to landscape.