Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Menu Inflate

meirrotfleischmeirrotfleisch USMember ✭✭✭

Hi
I added a folder under my Resources called "menu" and added my home.xml file

When I try

MenuInflater.Inflate(Resource.Menu.home, menu);

It says the resource Menu doesn't exist ..

I have done a "clean" "rebuild" but nothing helps

Suggestions Please

M.R.

Tagged:

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Please refer to following steps to create a Menu file.

    First of all, create a folder called menu in the Resources folder like following screenshot.

    Then right click the menu folder, add a new item.

    click the Android tab, select the Menu type file like following screenshot.

    In the end, Add you item.

    <?xml version="1.0" encoding="utf-8" ?>
    <!--For all properties see: https://aka.ms/android-menu-resource-->
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
      <item android:id="@+id/action_search"
             android:showAsAction="always"
             android:title="Search"
    
            />
    
    </menu>
    

    Open your activity, override the OnCreateOptionsMenu method.

      public override bool OnCreateOptionsMenu(IMenu menu)
            {
                MenuInflater.Inflate(Resource.Menu.menu1, menu);
                return true;
    
            }
    
    

    Here is my demo, you can test it.

    App5.zip 114.5K
Sign In or Register to comment.