Radek
Radek

Reputation: 133

Toolbar icons are not showing

I'm trying to use Toolbar in my app, I was able to follow android tutorial to the point of displaying these items as icons.

My Items shows as a sub menu of "..." on the right but no icon is shows. I tried using android:showAsAction="always" but I keep getting errors about issues with a name space and that I should use res-auto. When I tried that break my inflator of the menu and I was getting some strange title errors even though I had these tags defined.

Is there a way to display some icons on a toolbar and how can I force it with showAsAction=always without throwing errors.

Thank you

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item  
        android:id="@+id/favorite_ico"
        android:icon="@mipmap/ic_launcher"
        android:title="Item 1"
        android:showAsAction="ifRoom" />
    <item  
        android:id="@+id/settings_ico"
        android:title="Item 2" />
</menu>

Upvotes: 1

Views: 2623

Answers (3)

Ankush Bist
Ankush Bist

Reputation: 1892

if you are trying to use showAsAction="always"

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/favorite_ico"
        android:icon="@mipmap/ic_launcher"
        android:title="Item 1"
        app:showAsAction="always" />
    <item
        android:id="@+id/settings_ico"
        android:title="Item 2" />
</menu>

you need to import app not android

Upvotes: 2

Abhishek Singh
Abhishek Singh

Reputation: 9178

showAsAction should be from support library. for this purpose you need to use app:showAsAction. this need appNs

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto">
    <item  android:id="@+id/favorite_ico"
        android:icon="@mipmap/ic_launcher"
        android:title="Item 1"
        app:showAsAction="ifRoom">
    </item>
    <item  android:id="@+id/settings_ico"
         android:title="Item 2">
    </item>
</menu>

Upvotes: 1

Abhriya Roy
Abhriya Roy

Reputation: 1438

Please modify your code to this

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

    <item  
        android:id="@+id/favorite_ico"
        android:icon="@mipmap/ic_launcher"
        android:title="Item 1"
        app:showAsAction="ifRoom" />

    <item  
        android:id="@+id/settings_ico"
        android:title="Item 2" />
</menu>

Upvotes: 1

Related Questions