Ever Ever - 6 months ago 20
Android Question

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>

Answer

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>