void UpdateRightIcon(ToolbarItemEx itemEx, IMenuItem menuItem) { menuItem.SetVisible(true); menuItem.SetEnabled(itemEx.IsEnabled); if (string.IsNullOrEmpty(itemEx.Resource)) { return; } var image = SvgToBitmap.GetBitmap(itemEx.Resource, 24, 24); var icon = new BitmapDrawable(Context.Resources, image); menuItem.SetIcon(icon); if (!IsForeColorDefault && itemEx.IsEnabled) { menuItem.Icon.SetTint(ForeColor); } else if (!itemEx.IsEnabled) { menuItem.Icon.SetTint(ForeColor); menuItem.Icon.SetAlpha(80); } }
void UpdateLeftIcon(ToolbarItemEx itemEx, IMenuItem menuItem) { if (string.IsNullOrEmpty(itemEx.Resource)) { return; } var image = SvgToBitmap.GetBitmap(itemEx.Resource, 24, 24); var icon = new BitmapDrawable(Context.Resources, image); if (!IsForeColorDefault && itemEx.IsEnabled) { icon.SetTint(ForeColor); } else if (!itemEx.IsEnabled) { icon.SetTint(ForeColor); icon.SetAlpha(80); } //戻った時にこうしとかないと表示されない。BeginInvokeOnMainThreadだと失敗することがある。時間も250は必要。 Device.StartTimer(TimeSpan.FromMilliseconds(250), () => { _toolbar.NavigationIcon = icon; return(false); }); _navigationCustomListener?.Dispose(); _navigationCustomListener = new NavigationIconClickListener(itemEx.Command, itemEx.CommandParameter); _toolbar.SetNavigationOnClickListener(_navigationCustomListener); menuItem.SetVisible(false); }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); var fieldInfo = typeof(TabbedPageRenderer).GetField("_tabLayout", BindingFlags.Instance | BindingFlags.NonPublic); _tabs = (TabLayout)fieldInfo.GetValue(this); var teardownPage = typeof(TabbedPageRenderer).GetMethod("TeardownPage", BindingFlags.Instance | BindingFlags.NonPublic); _window = (Context as FormsAppCompatActivity).Window; if (e.OldElement != null) { } if (e.NewElement != null) { _tabbedEx = Element as TabbedPageEx; if (!_tabbedEx.IsDefaultColor) { //OnTabSelectedListenerを上書きする _tabs.SetOnTabSelectedListener(this); } // https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs#L297 // OnPagePropertyChangedでいらんことしてるので即TeardownPageを呼び出して解除する // (TabのTextを子ページのTitleと連動させているが、TabのTextはTabAttributeで設定するようにしているので不要) foreach (var page in Element.Children) { teardownPage.Invoke(this, new object[] { page }); } for (var i = 0; i < _tabbedEx.TabAttributes.Count; i++) { var attr = _tabbedEx.TabAttributes[i]; if (i == 0 && _tabbedEx.Parent is NavigationPageEx) { var navi = _tabbedEx.Parent as NavigationPageEx; navi.BarTextColor = _tabbedEx.BarTextColor; if (attr.BarTextColor != Xamarin.Forms.Color.Default) { navi.BarTextColor = attr.BarTextColor; } navi.StatusBarBackColor = _tabbedEx.StatusBarBackColor; if (attr.StatusBarBackColor != Xamarin.Forms.Color.Default) { navi.StatusBarBackColor = attr.StatusBarBackColor; } _tabbedEx.Title = (_tabbedEx.CurrentPage as Page).Title; _tabbedEx.CurrentPage.PropertyChanged += CurrentPage_PropertyChanged; var renderer = Platform.GetRenderer(navi) as NavigationPageExRenderer; renderer.UpdateMenu(); } if (string.IsNullOrEmpty(attr.Resource)) { continue; } var bitmap = SvgToBitmap.GetBitmap(attr.Resource, 24, 24); var icon = new BitmapDrawable(Context.Resources, bitmap); var tab = _tabs.GetTabAt(i); tab.SetIcon(icon); if (!_tabbedEx.IsDefaultColor || !attr.IsDefaultColor) { var color = _tabbedEx.SelectedColor.ToAndroid(); if (i == 0) { if (attr.SelectedColor != Xamarin.Forms.Color.Default) { color = attr.SelectedColor.ToAndroid(); } _tabs.SetSelectedTabIndicatorColor(color); if (_tabbedEx.StatusBarBackColor != Xamarin.Forms.Color.Default) { _window.SetStatusBarColor(_tabbedEx.StatusBarBackColor.ToAndroid()); } else if (attr.StatusBarBackColor != Xamarin.Forms.Color.Default) { _window.SetStatusBarColor(attr.StatusBarBackColor.ToAndroid()); } } else { color = _tabbedEx.UnSelectedColor.ToAndroid(); if (attr.UnSelectedColor != Xamarin.Forms.Color.Default) { color = attr.UnSelectedColor.ToAndroid(); } } tab.Icon.SetTint(color); _tabs.SetTabTextColors(_tabbedEx.UnSelectedTextColor.ToAndroid(), _tabbedEx.SelectedTextColor.ToAndroid()); } if (_tabbedEx.IsTextHidden) { tab.SetText(""); } } } }