How the renderers actually work

0

I have this toolbar. My difficulty is to change text into runtime and change font size and color.

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    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">
    <LinearLayout
        android:id="@+id/alternateTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:id="@+id/toolbarIcon" />
        <TextView
            android:id="@+id/alternateTitle1"
            android:text=""
            android:textSize="@dimen/notification_subtext_size"
            android:textColor="@color/material_deep_teal_500"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <TextView
            android:id="@+id/alternateTitle2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v7.widget.Toolbar>

So, on the advice of a colleague, I made this renderer

[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationRenderer))]
namespace Operacional.Droid
{
    public class NavigationRenderer : NavigationPageRenderer
    {
        private Support.Toolbar _toolbar;

        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            if (child.GetType() == typeof(Support.Toolbar))
                _toolbar = (Support.Toolbar)child;
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var page = this.Element as NavigationPage;

            if (page != null && _toolbar != null)
            {
                Typeface tf = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, "Arial.ttf");

                TextView title = (TextView)_toolbar.FindViewById(Resource.Id.alternateTitle1);
                title.SetText(page.CurrentPage.Title, TextView.BufferType.Normal);
                title.SetTypeface(tf, TypefaceStyle.Normal);
            }

        }

    }
}

But what's up? How is it used, how do I do what I need to do, type change font, text and etc? OBS : There are three questions, but how to use Renderer is the question.

    
asked by anonymous 28.02.2018 / 13:27

0 answers