如何隐藏Xamarin Android中硬件菜单按钮中的溢出图标

时间:2016-12-13 09:17:52

标签: xamarin xamarin.android

我需要在我的Xamarin Android应用程序中隐藏硬件菜单按钮中的溢出图标(三个点) - 参考屏幕截图。

我该怎么做?

enter image description here

2 个答案:

答案 0 :(得分:1)

我在nexus 6中找不到溢出图标,但我想给你一些建议:

对于xamarin android项目,Android.App.Activity在Java android的Activity之间是不同的。

我们可以在活动创建菜单时找到Android.App.Activity的源代码,它将调用以下函数:

// Summary:
//     Initialize the contents of the Activity's standard options menu.
//
// Parameters:
//   menu:
//     The options menu in which you place your items.
//
// Returns:
//     To be added.
//
// Remarks:
//     ///
//     Initialize the contents of the Activity's standard options menu. You /// should
//     place your menu items in to menu. /// ///
//     ///
//     This is only called once, the first time the options menu is /// displayed. To
//     update the menu every time it is displayed, see /// Android.App.Activity.OnPrepareOptionsMenu(Android.Views.IMenu).
//     /// ///
//     ///
//     The default implementation populates the menu with standard system /// menu items.
//     These are placed in the Android.Views.Menu.CATEGORY_SYSTEM group so that ///
//     they will be correctly ordered with application-defined menu items. /// Deriving
//     classes should always call through to the base implementation. /// ///
//     ///
//     You can safely hold on to menu (and any items created /// from it), making modifications
//     to it as desired, until the next /// time onCreateOptionsMenu() is called. ///
//     ///
//     ///
//     When you add items to the menu, you can implement the Activity's /// Android.App.Activity.OnOptionsItemSelected(Android.Views.IMenuItem)
//     method to handle them there.
//     ///
//     /// /// [Android Documentation] /// ///
//     ///
[Register("onCreateOptionsMenu", "(Landroid/view/Menu;)Z", "GetOnCreateOptionsMenu_Landroid_view_Menu_Handler")]
public virtual bool OnCreateOptionsMenu(IMenu menu);

onCreateOptionsMenu函数将被默认调用。 Xamarin android封装了Java Android的onCreateOptionsMenu功能。我认为你可以覆盖MainActivity中的函数,如下所示:

 public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
        }

        public override bool OnCreateOptionsMenu(Android.Views.IMenu menu)
        {
            return false;
        }
    }

应该创建默认菜单。

答案 1 :(得分:0)

这取决于特定设备及其操作系统,其中一些创建选项菜单,如您的设备,但一些在顶部的右上角