2
votes

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

enter image description here

Please suggest me how can I add title and button in action bar using xamarin form (Portable)

1
for tool bar you need to create _saveAddToolBarItem = new ToolbarItem() { Icon = Constants.ASSES_PLUS_ICON, }; _saveAddToolBarItem.Clicked += _saveAddImage_Clicked;sumeet
I dont want to add toolbar item. I change the question, added image so you can understand what i wantKirti Zare
there no any other option you need to use toolbar to add plus iconsumeet
Can please you tell me how to add toolbar or sent me link? How can i change action bar color? I wrote this code but not changing the color of the action bar. <ContentPage xmlns="xamarin.com/schemas/2014/forms" xmlns:x="schemas.microsoft.com/winfx/2009/xaml" x:Class="MUNI_Demo.View.Detail.Contact" Title="Contact" BackgroundColor="#42A990">Kirti Zare

1 Answers

2
votes

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

enter image description here Hop this code will help you

Approch to change toolbar color:

  Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) {
                    BarBackgroundColor = Color.FromHex("#42a990"),
                    BarTextColor = Color.White,
                };