How to show item icons on Android toolbar

I am having problems showing icons in the toolbar on Android. It shows a line, but not an 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>

      

+3


source to share


1 answer


you need to add this to your xml menu

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

      

then it android:showAsAction="always"

should look like this:



app:showAsAction="always"

      

the final conclusion will 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>

      

+12


source







All Articles