As mentioned in the title, the OnCreateOptionsMenu method is not called after I upgraded my system to Android 7.0.
Before upgrading, I used Android 6.0 and it worked without any problems. If I test it on another phone with 6.0, it still works (same code).
Are there any problems with this method on Android 7.0 or is there something wrong in my code?
The part of my MainActivity.cs where I installed the toolbar
[Activity(Label = "App", Icon = "@drawable/icon", MainLauncher = true, Theme = "@style/Theme.AppCompat.Light.NoActionBar",ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var toolbar = FindViewById<Android.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.SetTitleTextColor(Color.White);
SetActionBar(toolbar);
}
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.top_menu_start, menu);
return base.OnCreateOptionsMenu(menu);
}
}
Main.axml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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" />
</RelativeLayout>
top_menu_start
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/start_listview"
android:icon="@drawable/icon_posts_list"
android:showAsAction="ifRoom"
android:title="startListview" />
<item
android:id="@+id/start_pager"
android:icon="@drawable/icon_posts_kacheln"
android:showAsAction="ifRoom"
android:title="startPager" />
<item
android:id="@+id/doSomething"
android:icon="@drawable/icon"
android:showAsAction="ifRoom"
android:title="doSomething" />
</menu>
source
share