Hello,
Welcome to our Microsoft Q&A platform!
this method is never called whenever back button event is occurred. i am trying to call SetSupportActionBar() but it is giving error
What's the version of the Xamarin.Forms in your project? Xamarin.Forms 5.0 uses the AndroidX library by default. If the Target Framework of the Android platform project is set to Android 10, please use the AndroidX api instead. And place the SetSupportActionBar
code after the LoadApplication(new App())
line.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
...
LoadApplication(new App());
AndroidX.AppCompat.Widget.Toolbar toolbar = this.FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
return base.OnOptionsItemSelected(item);
}
...
}
For the first problem, I don't see the screenshot. Please re-post the file and share more details about the error.
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.