Menu Items are not showing on Action Bar

前端 未结 12 777
清歌不尽
清歌不尽 2020-11-29 20:57

I have made a completely new project. I have added items to the menu layout file. Those items do not show up on the action bar\'s right side. I remember that an

12条回答
  •  猫巷女王i
    2020-11-29 21:27

    What worked for me was changing a property in menu.xml

    
       
    

    this used to work in Material theme but didn't for AppCompat Theme & Activity so i changed how my menu.xml and add app:showAsAction= property under namespace `"http://schemas.android.com/apk/res-auto"

    
      
    

    from actvity inflate menu through OnCreateOptionsMenu(IMenu menu) and now from OnOptionsItemSelected() i can also get the selected item id as

     public override bool OnOptionsItemSelected(IMenuItem item)
            {
                    switch (item.ItemId)
                    {
                        case Resource.Id.gamingactivity_filter:
                            OnBackPressed();
                            break;
                    }
                }
                return true;
            }
    

提交回复
热议问题