void UpdateToolbarSubtitle(CustomPage cPage, AppCompatTextView subTitleTextView, Typeface originalFont, ColorStateList defaultColorStateList) { ClearTextView(subTitleTextView, true); if (cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0) { subTitleTextView.TextFormatted = cPage.FormattedSubtitle.ToAttributed(Font.Default, Xamarin.Forms.Color.Default, _subTitleTextView); subTitleTextView.Visibility = ViewStates.Visible; } else if (!string.IsNullOrEmpty(cPage.Subtitle)) { UpdateToolbarTextColor(subTitleTextView, CustomNavigationPage.GetSubtitleColor(cPage), _originalColorStateList); UpdateToolbarTextFont(subTitleTextView, CustomNavigationPage.GetSubtitleFont(cPage), _originalFont); subTitleTextView.Text = cPage.Subtitle; subTitleTextView.Visibility = ViewStates.Visible; } }
private void LastPage_PropertyChanged(object sender, PropertyChangedEventArgs e) { var lastPage = sender as Page; if (e.PropertyName == CustomNavigationPage.HasShadowProperty.PropertyName) { UpdateToolbarShadow(_toolbar, CustomNavigationPage.GetHasShadow(lastPage), Context as Activity, _originalWindowContent); } else if (e.PropertyName == CustomNavigationPage.TitleBackgroundProperty.PropertyName) { UpdateTitleViewLayoutBackground(_titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), _originalDrawable); } else if (e.PropertyName == CustomNavigationPage.BarBackgroundProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.GradientColorsProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.GradientDirectionProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.BarBackgroundOpacityProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.TitleBorderCornerRadiusProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleBorderWidthProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleBorderColorProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleFillColorProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitlePositionProperty.PropertyName) { UpdateTitleViewLayoutAlignment(_titleViewLayout, _titleTextView, _subTitleTextView, CustomNavigationPage.GetTitlePosition(lastPage)); //UpdateTitleViewLayout(lastPage, _titleViewLayout, _titleTextView, _subTitleTextView, _originalDrawable); } else if (e.PropertyName == CustomNavigationPage.TitlePaddingProperty.PropertyName) { UpdateTitleViewLayoutPadding(_titleViewLayout, CustomNavigationPage.GetTitlePadding(lastPage)); } else if (e.PropertyName == CustomNavigationPage.TitleMarginProperty.PropertyName) { UpdateTitleViewLayoutMargin(_titleViewLayout, CustomNavigationPage.GetTitleMargin(lastPage)); } else if (e.PropertyName == CustomNavigationPage.TitleColorProperty.PropertyName) { UpdateToolbarTextColor(_titleTextView, CustomNavigationPage.GetTitleColor(lastPage), _originalColorStateList); } else if (e.PropertyName == CustomNavigationPage.TitleFontProperty.PropertyName) { UpdateToolbarTextFont(_titleTextView, CustomNavigationPage.GetTitleFont(lastPage), _originalFont); } else if (e.PropertyName == Page.TitleProperty.PropertyName) { UpdateTitleText(_titleTextView, lastPage.Title); } else if (e.PropertyName == CustomPage.FormattedTitleProperty.PropertyName && (lastPage is CustomPage)) { var cPage = lastPage as CustomPage; UpdateFormattedTitleText(_titleTextView, cPage.FormattedTitle, cPage.Title); } else if (e.PropertyName == CustomNavigationPage.SubtitleColorProperty.PropertyName) { UpdateToolbarTextColor(_subTitleTextView, CustomNavigationPage.GetSubtitleColor(lastPage), _originalColorStateList); } else if (e.PropertyName == CustomNavigationPage.SubtitleFontProperty.PropertyName) { UpdateToolbarTextFont(_subTitleTextView, CustomNavigationPage.GetSubtitleFont(lastPage), _originalFont); } else if (e.PropertyName == CustomPage.SubtitleProperty.PropertyName && (lastPage is CustomPage)) { var cPage = lastPage as CustomPage; if (!string.IsNullOrEmpty(cPage.Subtitle)) { _subTitleTextView.Text = cPage.Subtitle; _subTitleTextView.Visibility = ViewStates.Visible; } else { ClearTextView(_subTitleTextView, true); } } else if (e.PropertyName == CustomPage.FormattedTitleProperty.PropertyName && (lastPage is CustomPage)) { var cPage = lastPage as CustomPage; if (cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0) { _subTitleTextView.TextFormatted = cPage.FormattedSubtitle.ToAttributed(Font.Default, Xamarin.Forms.Color.Default, _subTitleTextView); _subTitleTextView.Visibility = ViewStates.Visible; } else { ClearTextView(_subTitleTextView, true); } } }
void SetupTextFont(UILabel label, Font font, Color?titleColor) { var cPage = Element as CustomPage; if (cPage != null && cPage.FormattedTitle != null && cPage.FormattedTitle.Spans.Count > 0) { SetupFormattedText(titleLabel, cPage.FormattedTitle, cPage.Title); } else { SetupText(label, (Element as Page).Title, titleColor, CustomNavigationPage.GetTitleFont(Element)); } if (cPage != null && cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0) { subtitleLabel.Hidden = false; SetupFormattedText(subtitleLabel, cPage.FormattedSubtitle, cPage.Subtitle); } else if (cPage != null && !string.IsNullOrEmpty(cPage.Subtitle)) { subtitleLabel.Hidden = false; SetupText(subtitleLabel, cPage.Subtitle, CustomNavigationPage.GetSubtitleColor(cPage), CustomNavigationPage.GetSubtitleFont(Element)); subtitleLabel.SetNeedsDisplay(); } else { subtitleLabel.Text = string.Empty; subtitleLabel.Frame = CGRect.Empty; subtitleLabel.Hidden = true; } label.SizeToFit(); subtitleLabel.SizeToFit(); titleView.SizeToFit(); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var lastPage = Element.CurrentPage; if (e.PropertyName == CustomNavigationPage.HasShadowProperty.PropertyName) { UpdateToolbarShadow(_toolbar, CustomNavigationPage.GetHasShadow(lastPage), Context as Activity, _originalWindowContent); } else if (e.PropertyName == CustomNavigationPage.TitleBackgroundProperty.PropertyName) { UpdateTitleViewLayoutBackground(_titleViewLayout, CustomNavigationPage.GetTitleBackground(lastPage), _originalDrawable); } else if (e.PropertyName == CustomNavigationPage.BarBackgroundProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.GradientColorsProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.GradientDirectionProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.BarBackgroundOpacityProperty.PropertyName) { UpdateToolbarBackground(_toolbar, lastPage, Context as Activity, _originalToolbarBackground); } else if (e.PropertyName == CustomNavigationPage.TitleBorderCornerRadiusProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleBorderWidthProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleBorderColorProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitleFillColorProperty.PropertyName) { _titleViewLayout?.SetBackground(CreateShape(ShapeType.Rectangle, (int)CustomNavigationPage.GetTitleBorderWidth(lastPage), (int)CustomNavigationPage.GetTitleBorderCornerRadius(lastPage), CustomNavigationPage.GetTitleFillColor(lastPage), CustomNavigationPage.GetTitleBorderColor(lastPage))); } else if (e.PropertyName == CustomNavigationPage.TitlePositionProperty.PropertyName) { UpdateTitleViewLayoutAlignment(_titleViewLayout, _titleTextView, _subTitleTextView, CustomNavigationPage.GetTitlePosition(lastPage)); } else if (e.PropertyName == CustomNavigationPage.TitlePaddingProperty.PropertyName) { UpdateTitleViewLayoutPadding(_titleViewLayout, CustomNavigationPage.GetTitlePadding(lastPage)); } else if (e.PropertyName == CustomNavigationPage.TitleMarginProperty.PropertyName) { UpdateTitleViewLayoutMargin(_titleViewLayout, CustomNavigationPage.GetTitleMargin(lastPage)); } else if (e.PropertyName == CustomNavigationPage.TitleColorProperty.PropertyName) { UpdateToolbarTextColor(_titleTextView, CustomNavigationPage.GetTitleColor(lastPage), _originalColorStateList); } else if (e.PropertyName == CustomNavigationPage.TitleFontProperty.PropertyName) { UpdateToolbarTextFont(_titleTextView, CustomNavigationPage.GetTitleFont(lastPage), _originalFont); } else if (e.PropertyName == Page.TitleProperty.PropertyName) { UpdateTitleText(_titleTextView, lastPage.Title); } else if (e.PropertyName == CustomNavigationPage.SubtitleColorProperty.PropertyName) { UpdateToolbarTextColor(_subTitleTextView, CustomNavigationPage.GetSubtitleColor(lastPage), _originalColorStateList); } else if (e.PropertyName == CustomNavigationPage.SubtitleFontProperty.PropertyName) { UpdateToolbarTextFont(_subTitleTextView, CustomNavigationPage.GetSubtitleFont(lastPage), _originalFont); } }