Reputation: 729
I am using xamarin.form (Portable) having two project android and ios.
I want to add title in action bar which will change according to detail page also want to add one button in right side in action bar
I refer below link
https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage
This link help me to create navigation page. but not able to add title and button in action bar
Below is image of action bar that I want. Payment is a title which can be change according to detail page and on right side "+" is button
Please suggest me how can I add title and button in action bar using xamarin form (Portable)
Upvotes: 3
Views: 5584
Reputation: 305
You need to create page like there is not any other option to add plus sign without using a toolbar item in master detail page
Following is some sample code
public class TodoListPageCS : ContentPage
{
private ToolbarItem _saveAddToolBarItem;
public TodoListPageCS ()
{
Title = "Page Name";
_saveAddToolBarItem = new ToolbarItem()
{ Text = "Save"};
ToolbarItems.Add(_saveAddToolBarItem);
_saveAddToolBarItem.Clicked += _saveAddToolBarItem_Clicked;
Content = new StackLayout {
Children = {
new Label {
Text = "Todo list data goes here",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
}
}
};
}
private void _saveAddToolBarItem_Clicked(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
}
Otherwise, you need to create your own custom base page instead of content page
To changing toolbar color refer following link: https://forums.xamarin.com/discussion/44586/navigationbar-background-image-renderer-android
Approch to change toolbar color:
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) {
BarBackgroundColor = Color.FromHex("#42a990"),
BarTextColor = Color.White,
};
Upvotes: 2