Как сделать текст на панели навигации жирным? - PullRequest
0 голосов
/ 20 декабря 2018

У меня есть архитектура Master-Detail, и мне нужно сделать текст заголовка страницы сведений жирным шрифтом.Как я могу сделать это самым простым способом?

Вот часть моего кода:

    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;
    }

Ответы [ 3 ]

0 голосов
/ 21 декабря 2018

Для IOS вы должны просто сделать это.в FinishedLaunching проекта IOS вам нужно поставить UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.SystemFontOfSize(18.0f, UIFontWeight.Heavy) };

перед LoadApplication(new App());

0 голосов
/ 21 декабря 2018

Мне было дано решение здесь:

https://forums.xamarin.com/discussion/comment/358994#Comment_358994

Это делается с помощью TitleView:

        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);
0 голосов
/ 21 декабря 2018

Для части Android вы можете реализовать эту функцию, добавив в ваш файл Resources\values\styles.xml следующее:

<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>

Затем добавьте его в 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"/>
...