0

I'm using AndroidX Navigation architecture and want to know is it possible to replace the ActionBar menu completely or not?

In the project, in the Menu directory, there is a home.xml file that contains a menu items:

<?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"
android:id="@+id/homeMainMenu">
<item
    android:id="@+id/action_inbox"
    android:icon="@drawable/ic_baseline_mail_outline_24"
    android:title="@string/action_inbox"
    app:showAsAction="ifRoom" />
<item android:icon="@drawable/ic_baseline_more_vert_24"
    android:title="@string/app_name"
    app:showAsAction="always">
    <menu>
        <item
        android:id="@+id/action_exitapp"
        android:icon="@drawable/ic_baseline_exit_to_app_24"
        android:title="@string/action_exit"
        app:showAsAction="never" />
         </menu>
     </item>
</menu>

I want to create another menu XML file like mymenu.xml and on the fragment replace it with the home menu. Because of some reason don't want to replace items. Is it possible? If "Yes" how to handle item click?

motevalizadeh
  • 5,244
  • 14
  • 61
  • 108

1 Answers1

1

If i got your question correct then i guess you want to create different menu for activity and its fragment. You can do that. Please check here

Remember you've to add hasOptionsMenu in fragment onCreate

Naveen Rao
  • 712
  • 6
  • 10