Reputation: 8201
I am trying to set the tile of the Android.Support.V7.App ActionBar under AppCompatActivity using the following code for Xamarin.Android. It is not working for me.
SupportActionBar.Title = "";
Can anyone please guide me to resolve the issue.
Upvotes: 2
Views: 556
Reputation: 1849
Here is my code that does the job. I initialize the title in the OnCreateOptionsMenu method, not in the OnCreate method.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(LayoutResource);
Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
if (Toolbar != null)
{
SetSupportActionBar(Toolbar);
Toolbar.SetOnMenuItemClickListener(this);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
SupportActionBar.SetDisplayShowHomeEnabled(true);
}
}
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(MenuId, menu);
Toolbar.Title = "my title";
return base.OnCreateOptionsMenu(menu);
}
Upvotes: 2