Menu icon image does not appear in action bar

Asked 2 years ago, Updated 2 years ago, 53 views

I want the icon to appear in the action bar as it is written here, but it doesn't show well.
Currently, only menu icons (vertical "...") are displayed, not icons.I'd like to change this to an update icon (an image I prepared separately), but it doesn't work.
I'm using the linked source as it is, so I'll skip it now, but I'll show it to you if necessary.
Please let me know.

android java

2022-09-29 20:26

2 Answers

@Override
public boolean onCreateOptionsMenu(Menu){
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return super.onCreateOptionsMenu(menu);
}

Is written in Activity?


2022-09-29 20:26

The contents of the linked "res/menu/activity_main.xml" are as follows, but

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

    <item
        android: id="@+id/menu_refresh"
        android:icon="@drawable/ic_action_refresh"
        android:orderInCategory="100"
        android:showAsAction="always"
        android: title="@string/menu_refresh"/>

</menu>

If you are using the appcompat-v7 support library,

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

    <item
        android: id="@+id/menu_refresh"
        android:icon="@drawable/ic_action_refresh"
        android:orderInCategory="100"
        app:showAsAction="always"
        android: title="@string/menu_refresh"/>

</menu>

It must be said that(Added "xmlns:app=..."; changed "android:showAsAction" to "app:showAsAction")
How about there?


2022-09-29 20:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.