How can I make my navigation bar text bold?

Dear experts,

I have a Master-Detail architecture, and I need to make the detail page's title text of the navigation bar bold. How can I do that the simplest way?

Here is some of my code:

        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = e.SelectedItem as MainMDPageMenuItem;
            if (item == null)
                return;

            item.ItemBorderColor = Color.Red; // Make a red frame around the selected item
            if (PreviouslySelectedItem != null)
            {
                PreviouslySelectedItem.ItemBorderColor = Color.FromHex("#00a8d5"); // Return the original color to the previously selected (now deselected) item
            }

            var page = (Page)Activator.CreateInstance(item.TargetType);
            page.Title = item.Title; // THIS IS THE TITLE I AM TALKING ABOUT

            Detail = new NavigationPage(page);
            IsPresented = false;

            MasterPage.ListView.SelectedItem = null;

            PreviouslySelectedItem = item;
        }

Thanks.

Best Answer

Answers

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai

    For Android part, you could implement this feature by add the following in your Resources\values\styles.xml file:

    <style name="ActionBar.nameText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">58sp</item> <-- Could delete this line
        <item name="android:textStyle">bold</item>
      </style>
    

    Then, add it in your Resources\layout\Toolbar.axml:

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:companyApp="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
        companyApp:titleTextAppearance="@style/ActionBar.nameText"/>
    
    
    
  • dpreznikdpreznik Member ✭✭

    @YorkGo said:
    For Android part, you could implement this feature by add the following in your Resources\values\styles.xml file:

    Thank you for your answer. But I don't use Android, I use UWP.

  • dpreznikdpreznik Member ✭✭
    edited December 2018

    @JamesLavery said:
    Can't you use a TitleView for the page? A TitleView allows you to specify the content of the page's navigation header.

    I'm not sure how it works with MasterDetail page's though.

    Yes, this works! Thanks! I use it like this:

                var page = (Page)Activator.CreateInstance(item.TargetType);
    
                var titleView = new Label
                {
                    Text = item.Title,
                    FontAttributes = FontAttributes.Bold,
                    TextColor = Color.White,
                    BackgroundColor = Color.FromHex("#00a8d5")
                };
    
                NavigationPage.SetTitleView(page, titleView);
    
Sign In or Register to comment.