Skip to content Skip to sidebar Skip to footer

Oncreateoptionsmenu Doesn't Get Called On Android 7.0

As in the title mentioned the OnCreateOptionsMenu method doesn't get called after I updated my system to Android 7.0. Before the update I used Android 6.0 and it worked without any

Solution 1:

Since you are using AppCompatActivity you should be using Android.Support.V7.Widget.Toolbar instead of Android.Widget.Toobar and calling SetSupportActionBar instead of SetActionBar. Now your OnCreateOptionsMenu will be called.

OnCreate override:

base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.SetTitleTextColor(Color.White);
SetSupportActionBar(toolbar);

Main.axml update:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#1D1D1D"        android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar">
    </android.support.v7.widget.Toolbar>

Post a Comment for "Oncreateoptionsmenu Doesn't Get Called On Android 7.0"