Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show item icons on toolbar Android

I am having some problems showing icons in the toolbar on Android It shows the string, but not the icon.

XML:

<item android:id="@+id/bno_bookmark"
    android:visible="true"
    android:title="@string/disable_draw"
    android:icon="@drawable/ic_pen"
    android:showAsAction="always">
</item>
like image 709
Ever Avatar asked Dec 08 '22 05:12

Ever


1 Answers

you need to add this to your menu xml

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

then android:showAsAction="always" should look like this

app:showAsAction="always"

final output would be something like this

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/bno_bookmark"
        android:visible="true"
        android:title="@string/disable_draw"
        android:icon="@drawable/ic_pen"
        app:showAsAction="always">
    </item>
</menu>
like image 65
tyczj Avatar answered Dec 27 '22 09:12

tyczj