public void DisableShiftMode(BottomNavigationView v) { var menu = (BottomNavigationMenuView)((ViewGroup)v).GetChildAt(0); var shiftingMode = menu.Class.GetDeclaredField("mShiftingMode"); shiftingMode.Accessible = true; shiftingMode.SetBoolean(menu, false); shiftingMode.Accessible = false; for (int i = 0; i < menu.ChildCount; i++) { BottomNavigationItemView item = (BottomNavigationItemView)menu.GetChildAt(i); item.SetShiftingMode(false); item.SetChecked(item.ItemData.IsChecked); //TextView var content = (BaselineLayout)item.GetChildAt(1); content.LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(Android.Widget.FrameLayout.LayoutParams.MatchParent, Android.Widget.FrameLayout.LayoutParams.MatchParent); for (int j = 0; j < content.ChildCount; j++) { var tv = (AppCompatTextView)content.GetChildAt(j); tv.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); tv.SetTextSize(Android.Util.ComplexUnitType.Px, tv.TextSize * 1.2f); tv.TextAlignment = Android.Views.TextAlignment.Center; tv.Gravity = GravityFlags.Center; tv.Typeface = Android.Graphics.Typeface.DefaultBold; } item.RemoveView(item.GetChildAt(0)); } menu.UpdateMenuView(); }
public static void disableShiftMode(BottomNavigationView view) { BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0); try { for (int i = 0; i < menuView.ChildCount; i++) { BottomNavigationItemView item = (BottomNavigationItemView)menuView.GetChildAt(i); //noinspection RestrictedApi item.SetShiftingMode(false); // set once again checked value, so view will be updated //noinspection RestrictedApi item.SetChecked(item.ItemData.IsChecked); } } catch (NoSuchFieldException e) { //Log.("BNVHelper", "Unable to get shift mode field", e); } catch (IllegalAccessException e) { // Log.e("BNVHelper", "Unable to change value of shift mode", e); } }
public static void disableShiftMode(BottomNavigationView navigationView) { BottomNavigationMenuView menuView = (BottomNavigationMenuView)navigationView.GetChildAt(0); try { var shiftingMode = typeof(BottomNavigationMenuView).GetField("mShiftingMode"); //shiftingMode.setAccessible(true); //shiftingMode.setBoolean(menuView, false); //shiftingMode.SetValue(menuView, false); //shiftingMode.setAccessible(false); for (int i = 0; i < menuView.ChildCount; i++) { BottomNavigationItemView itemView = (BottomNavigationItemView)menuView.GetChildAt(i); itemView.SetShiftingMode(false); itemView.SetChecked(itemView.ItemData.IsChecked); } } catch (Exception ex) { throw; } }
private void SettingUpMenu() { try { var menuView = bottombar.GetChildAt(0) as BottomNavigationMenuView; if (menuView.ChildCount == 4) { BottomNavigationItemView item1 = (BottomNavigationItemView)menuView.GetChildAt(0); BottomNavigationItemView item2 = (BottomNavigationItemView)menuView.GetChildAt(1); BottomNavigationItemView item3 = (BottomNavigationItemView)menuView.GetChildAt(2); BottomNavigationItemView item4 = (BottomNavigationItemView)menuView.GetChildAt(3); item1.SetPadding(0, 0, 20, 0); item2.SetPadding(0, 0, 20, 0); item3.SetPadding(20, 0, 0, 0); item4.SetPadding(20, 0, 0, 0); } else if (menuView.ChildCount == 2) { BottomNavigationItemView item1 = (BottomNavigationItemView)menuView.GetChildAt(0); BottomNavigationItemView item2 = (BottomNavigationItemView)menuView.GetChildAt(1); item1.SetPadding(0, 0, 20, 0); item2.SetPadding(20, 0, 0, 0); } else { throw new Exception("Items should be equal to 2 or 4"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
void SetTabItemTextColor(BottomNavigationItemView bottomNavigationItemView, Android.Graphics.Color textColor) { var itemTitle = bottomNavigationItemView.GetChildAt(1); var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0)); var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1)); smallTextView.SetTextColor(textColor); largeTextView.SetTextColor(textColor); }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); var metrics = Resources.DisplayMetrics; var width = metrics.WidthPixels; floatingActionButton = new FloatingActionButton(this.Context); var layoutParams = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); LayoutParams paramss = new LayoutParams( LayoutParams.WrapContent, LayoutParams.WrapContent ); MarginLayoutParams marginLayout = new MarginLayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); marginLayout.SetMargins((int)(width / 2.3), 0, 0, 40); floatingActionButton.BackgroundTintList = Context.GetColorStateList(Resource.Color.blueColor); floatingActionButton.Click += FloatingActionButton_Click; floatingActionButton.LayoutParameters = marginLayout; floatingActionButton.SetBackgroundColor(Android.Graphics.Color.Blue); floatingActionButton.SetImageResource(Resource.Drawable.plus_white); floatingActionButton.SetForegroundGravity(GravityFlags.Center); floatingActionButton.Elevation = 6; var layout = (GetChildAt(0) as Android.Widget.RelativeLayout); RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); p.AddRule(LayoutRules.AlignBottom); //layout.AddView(floatingActionButton); var bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView; //ViewGroupUtils.removeView(bottomNavigationView); //var b = LayoutInflater.From(this.Context).Inflate(Resource.Layout.MaterialBottomAppBar, null); //layout.AddView(b,1); bottomNavigationView.SetClipChildren(false); var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView; BottomNavigationItemView item2 = (BottomNavigationItemView)menuView.GetChildAt(1); BottomNavigationItemView item3 = (BottomNavigationItemView)menuView.GetChildAt(2); item2.SetPadding(0, 0, 100, 0); item3.SetPadding(100, 0, 0, 0); //item2.SetPaddingRelative(0, 0, 300, 0); //for (int i = 0; i < menuView.ChildCount; i++) //{ // BottomNavigationItemView item = (BottomNavigationItemView)menuView.GetChildAt(i); // item.SetPadding(0, 0, 50, 0); // //noinspection RestrictedApi // item.SetShifting(false); // // set once again checked value, so view will be updated // //noinspection RestrictedApi // item.SetChecked(item.ItemData.IsChecked); //} bottomNavigationView.AddView(floatingActionButton); }
private void UpdateTabColor(Page page, Xamarin.Forms.Color color, BottomNavigationItemView itemView) { if (itemView == null) { return; } var nativeColor = ColorStateList.ValueOf(color.ToAndroid()); itemView.SetIconTintList(nativeColor); itemView.SetTextColor(nativeColor); }
/// <summary> /// Initialization of Bottom Menu /// </summary> private void BottomMenuInitializer() { BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation); navigation.SetOnNavigationItemSelectedListener(this); BottomNavigationItemView itemCompare = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_compare); BottomNavigationItemView itemStatistics = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_statistics); BottomNavigationItemView itemFeedback = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_feedback); itemCompare.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#707070"))); itemStatistics.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#707070"))); itemFeedback.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#dc3546"))); }
/// <summary> /// The ApplyBadge. /// </summary> /// <param name="bottomNavigationView">The bottomNavigationView<see cref="BottomNavigationItemView"/>.</param> /// <param name="color">The color<see cref="XColor"/>.</param> /// <param name="text">The text<see cref="string"/>.</param> /// <param name="textColor">The textColor<see cref="XColor"/>.</param> public static void ApplyBadge(this BottomNavigationItemView bottomNavigationView, XColor color, string text, XColor textColor) { if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any()) { bottomNavigationView.SetClipChildren(false); bottomNavigationView.SetClipToPadding(false); ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single(); bottomNavigationView.RemoveView(imageView); FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context) { LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent) { Gravity = GravityFlags.CenterHorizontal } }; badgeContainerFrameLayout.AddView(imageView); BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context); badgeContainer.TopMargin = 20; badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, color); badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, text, textColor)); badgeContainerFrameLayout.AddView(badgeContainer); bottomNavigationView.AddView(badgeContainerFrameLayout); } else { BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single(); badgeContainer.TopMargin = 20; badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid(); TextView textView = (TextView)badgeContainer.GetChildAt(0); textView.Text = text; textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid()); textView.SetTextSize(ComplexUnitType.Sp, 10); } }
/// <summary> /// The ApplyTinyBadge. /// </summary> /// <param name="bottomNavigationView">The bottomNavigationView<see cref="BottomNavigationItemView"/>.</param> /// <param name="textColor">The textColor<see cref="XColor"/>.</param> public static void ApplyTinyBadge(this BottomNavigationItemView bottomNavigationView, XColor textColor) { if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any()) { bottomNavigationView.SetClipChildren(false); bottomNavigationView.SetClipToPadding(false); ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single(); bottomNavigationView.RemoveView(imageView); FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context) { LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent) { Gravity = GravityFlags.CenterHorizontal } }; badgeContainerFrameLayout.AddView(imageView); BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context); badgeContainer.TopMargin = 24; badgeContainer.Visibility = ViewStates.Visible; badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, XColor.Transparent); badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, "●", textColor, 20)); badgeContainerFrameLayout.AddView(badgeContainer); bottomNavigationView.AddView(badgeContainerFrameLayout); } else { BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single(); badgeContainer.TopMargin = 24; badgeContainer.Visibility = ViewStates.Visible; ((PaintDrawable)badgeContainer.Background).Paint.Color = XColor.Transparent.ToAndroid(); TextView textView = (TextView)badgeContainer.GetChildAt(0); textView.Text = "●"; textView.SetTextSize(ComplexUnitType.Sp, 20); textView.SetTextColor(textColor.ToAndroid()); } }
public static void DisableShiftMode(BottomNavigationView view) { BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0); try { var sm = menuView.Class.GetDeclaredField("mShiftingMode"); sm.Accessible = true; sm.SetBoolean(menuView, false); sm.Accessible = false; for (int i = 0; i < menuView.ChildCount; i++) { BottomNavigationItemView item = (BottomNavigationItemView)menuView.GetChildAt(i); item.SetShiftingMode(false); item.SetChecked(item.ItemData.IsChecked); } } catch (System.Exception) { } }
public static void DisableShiftMode(BottomNavigationView view) { BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0); try { Java.Lang.Reflect.Field shiftingMode = menuView.Class.GetDeclaredField("mShiftingMode"); shiftingMode.Accessible = true; shiftingMode.SetBoolean(menuView, false); shiftingMode.Accessible = false; for (int i = 0; i < menuView.ChildCount; i++) { BottomNavigationItemView itemView = (BottomNavigationItemView)menuView.GetChildAt(i); itemView.SetShiftingMode(false); itemView.SetChecked(itemView.ItemData.IsChecked); } } catch (Exception ex) { BuglyUtil.PostException("unable to get shift mode field" + ex); } }
/// <summary> /// Initialization of Bottom Menu /// </summary> private void BottomMenuInitializer() { BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation); navigation.SetOnNavigationItemSelectedListener(this); BottomNavigationItemView itemCompare = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_compare); BottomNavigationItemView itemStatistics = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_statistics); BottomNavigationItemView itemFeedback = navigation.FindViewById <BottomNavigationItemView>(Resource.Id.navigation_feedback); itemCompare.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#707070"))); itemStatistics.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#dc3546"))); itemFeedback.SetIconTintList(ColorStateList.ValueOf(Color.ParseColor("#707070"))); chartbutton = FindViewById <Button>(Resource.Id.chartbutton); statbutton = FindViewById <Button>(Resource.Id.statbutton); statbutton.Click += (s, e) => { StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://play.google.com/store/apps/details?id=com.wave.skillmeter"))); }; chartbutton.Click += (s, e) => { StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://play.google.com/store/apps/details?id=com.wtwave.wtinsider"))); }; }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); BottomTabbedPage formsPage = (BottomTabbedPage)Element; if (!formsPage.Labels) { var childViews = ViewGroup.GetViewsByType(typeof(BottomNavigationItemView)); foreach (var childView in childViews) { childView.FindAndRemoveById(Resource.Id.largeLabel); childView.FindAndRemoveById(Resource.Id.smallLabel); } } if (e.NewElement != null) { var relativeLayout = this.GetChildAt(0) as Android.Widget.RelativeLayout; if (relativeLayout != null) { var bottomNavigationView = relativeLayout.GetChildAt(1) as BottomNavigationView; bottomNavigationView.SetShiftMode(false, false); BottomNavigationMenuView bottomNavigationMenuView = (BottomNavigationMenuView)bottomNavigationView.GetChildAt(0); int tabCount = formsPage.Tabs.Count; for (int i = 0; i < tabCount; i++) { var tabData = formsPage.Tabs[0]; BottomNavigationItemView tabItemView = (BottomNavigationItemView)bottomNavigationMenuView.GetChildAt(i); if (tabData.BadgeCaption > 0) { if (_badgeId == 0) { _badgeId = Android.Views.View.GenerateViewId(); } TextView badgeTextView = new BadgeView(Context) { Id = _badgeId, BadgeCaption = tabData.BadgeCaption.ToString(), BadgeColor = tabData.BadgeColor.ToAndroid() }; tabData.PropertyChanged += (sender, args) => { TabData currentTabData = (TabData)sender; BottomNavigationItemView currentTabItemView = _tabViews[currentTabData]; BadgeView currentBadgeTextView = currentTabItemView.FindViewById(_badgeId) as BadgeView; if (currentBadgeTextView != null) { currentBadgeTextView.BadgeColor = currentTabData.BadgeColor.ToAndroid(); currentBadgeTextView.BadgeCaption = currentTabData.BadgeCaption > 0 ? currentTabData.BadgeCaption.ToString() : string.Empty; } }; tabItemView.AddView(badgeTextView); _tabViews.Add(tabData, tabItemView); } } } } }
private void UpgradeTabbedItemsAppereance() { if (bottomTabBarItemsStateList == null) { InitializeBottomTabBarItemsStateList(); } if (ViewGroup != null && ViewGroup.ChildCount > 0) { BottomNavigationView bottomNavigationView = FindChildOfType <BottomNavigationView>(ViewGroup); bottomNavigationView.SetShiftMode(false, false); BottomNavigationMenuView bottomNavigationMenuView = FindChildOfType <BottomNavigationMenuView>(ViewGroup); for (int i = 0; i < bottomNavigationMenuView.ChildCount; i++) { BottomNavigationItemView item = (BottomNavigationItemView)bottomNavigationMenuView.GetChildAt(i); item.SetTextColor(bottomTabBarItemsStateList); item.SetShifting(false); item.SetLabelVisibilityMode(LabelVisibilityMode.LabelVisibilityLabeled); item.SetChecked(item.ItemData.IsChecked); Android.Views.View activeLabel = item.FindViewById(Resource.Id.largeLabel); if (activeLabel is TextView) { var font = Typeface.CreateFromAsset(_context.Assets, "Montserrat-SemiBold.ttf"); (activeLabel as TextView).Typeface = font; } Android.Views.View inActiveLabel = item.FindViewById(Resource.Id.smallLabel); if (activeLabel is TextView) { var font = Typeface.CreateFromAsset(_context.Assets, "Montserrat-SemiBold.ttf"); (inActiveLabel as TextView).Typeface = font; } } } T FindChildOfType <T>(ViewGroup viewGroup) where T : Android.Views.View { if (viewGroup == null || viewGroup.ChildCount == 0) { return(null); } for (var i = 0; i < viewGroup.ChildCount; i++) { var child = viewGroup.GetChildAt(i); var typedChild = child as T; if (typedChild != null) { return(typedChild); } if (!(child is ViewGroup)) { continue; } var result = FindChildOfType <T>(child as ViewGroup); if (result != null) { return(result); } } return(null); } }