Tabs - James Montemagno https://staging.montemagno.com/tag/tabs/ https://staging.montemagno.com/content/images/2017/08/MonogramIcon_Orange_NoBuffer.png Tabs - James Montemagno https://staging.montemagno.com/tag/tabs/ Hugo -- gohugo.io Tue, 13 Oct 2026 23:21:57 GMT 60 Control Text Size on Android Bottom Navigation View https://staging.montemagno.com/control-text-size-on-android-bottom-navigation/ 5c7f7cab720b5500bfd5d63a Wed, 06 Mar 2019 16:16:00 GMT It seems as though my obsession with the Android Bottom Navigation View aka Bottom Tabs will never end! This time I got a question about controlling the size of the text when the user taps on a tab. The default behavior is to zoom in on the text:

Before

Inside of your Android project's Resources/values folder create a new file called dimens.xml if it doesn't exist. Then add the following XML to override the size of the text when it is active and not active:

<resources xmlns:tools="http://schemas.android.com/tools">
    <dimen name="design_bottom_navigation_text_size" tools:override="true">12sp</dimen>
    <dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen>
</resources>

After

Now for this to work you must be using Android Support libraries version 28 and higher. You also most likely want to turn off shifting. Enjoy and don't forget to read all about Bottom Tabs on the official documentation.

]]>
Xamarin.Forms: Fully Customize Bottom Tabs on Android & Turn Off Shifting https://staging.montemagno.com/xamarin-forms-fully-customize-bottom-tabs-on-android-turn-off-shifting/ 5c6de28e720b5500bfd5d622 Fri, 22 Feb 2019 00:15:00 GMT

It seems as if the BottomNavigationView aka Bottom Tabs on Android is one of the top things that I write about on my blogs. There was an introduction post, how to use reflection to remove shifting on native Xamarin.Android, official support in Xamarin.Forms, and most recently how to get a nice drop shadow. I am back one more time to talk specifically about how to finely tune those bottom tabs on android and stop the ridiculous default Android behavior of shifting the tab icons and text.

BottomNavFixed-1

Let's start with the problem. If you have more than 3 tabs in your bottom navigation view (aka bottom tabs) then the text of the icons vanishes and you are left with just the icons that "shift". As you can see from this example it is kind of annoying:

Shifting

What is very interesting is that not a single Google specific app that uses bottom tabs has the shift on at all. To adjust this behavior it used to be extremely difficult and required a bunch of Java reflection (which is no fun). However, in the most recent Android Support 28 libraries Google fixed it with the LabelVisibilityMode. So first things first, make sure you are set to compile against Android 9.0 and update those Support Libraries:

Compile: Compile

Libraries: Libs

Now, we just need to write a simple effect to apply to our Xamarin.Forms TabbedPage (no renderer required!).

Here is our base NoShiftEffect.cs inside of our Android project:

using Android.Support.Design.BottomNavigation;
using Android.Support.Design.Widget;
using Android.Views;
using App16.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly:ResolutionGroupName ("MyCompany")]
[assembly:ExportEffect (typeof(NoShiftEffect), "NoShiftEffect")]
namespace App16.Droid
{
    public class NoShiftEffect : PlatformEffect
    {
        protected override void OnAttached ()
        {
            if (!(Container.GetChildAt(0) is ViewGroup layout))
                return;

            if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView))
                return;

            // This is what we set to adjust if the shifting happens
            bottomNavigationView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled;
        }

        protected override void OnDetached ()
        {
        }
    }
}

Now inside of your shared code create the Routing Effect:

using Xamarin.Forms;

namespace App16
{
    public class NoShiftEffect : RoutingEffect
    {
        public NoShiftEffect() : base("MyCompany.NoShiftEffect")
        {
        }
    }
}

And finally add the effect:

<TabbedPage.Effects>
    <local:NoShiftEffect />
</TabbedPage.Effects>

Using LabelVisibilityLabeled for the mode will turn off shifting and properly display the labels:

Tabs

Here is what the other modes do:

  • LabelVisibilityAuto: Label behaves as "labeled" when there are 3 items or less, or "selected" when there are 4 items or more.
  • LabelVisibilityLabeled: Label is shown on all navigation items.
  • LabelVisibilitySelected: Label is shown on the selected navigation item.
  • LabelVisibilityUnlabled: Label is not shown on any navigation items.

Here is what the last one looks like:

NoLabels

If you are using an older version of the support libraries then you can fall back on my old reflection trick and a custom renderer.

I think that is it! I think I can retire from bottom tabs for now! Enjoy and don't forget to read all about Bottom Tabs on the official documentation.

]]>
Xamarin.Forms: Official Bottom Navigation/Bottom Tabs on Android https://staging.montemagno.com/xamarin-forms-official-bottom-navigation-bottom-tabs-on-android/ 5b46cd40b2b69200bf058c0b Tue, 17 Jul 2018 18:34:00 GMT

Bottom tabs on Android... Love them... Hate them... it doesn't matter because Google seems to be all in on them. Top tabs were really designed to sort differerent types of data, while bottom tabs make a lot of sense when you want to use them for your entire application's navigation. It also has the perk that it synchronizes your application design and navigation with the iOS counterpart.

Since Xamarin.Forms maps to the native controls, when you create a Tabbed Page you get the tabs exactly where you would expect:

Tabs

Look at how pretty those tabs are! Woooo! Alright, but let's say you want them to be on the bottom. While it was possible (everything is possible with a custom renderer) it took a lot of work to get bottom tabs on Android. Then magically Xamarin.Forms 3.1 was released with a few new magical properties that developers can set on the TabbedPage and also some new Platform Specifics for Xamarin.Forms to enable this funcationality. Let's take a look!

Toolbar Placement

It is now surprisingly easy to get those tabs down on the bottom with a platform specific:

XAML:

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
    android:TabbedPage.ToolbarPlacement="Bottom"

Note: You may get blue underlines that ToolbarPlacement or others can't be found. This is a weird intellisense issue because they aren't properties and are actual constructor arguments. Don't worry, they work just fine!

Or in C# code behind:

using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;

On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

BottomTabs-1

Just like that our tabs are on the bottom and everyone is happy!

Note that I also added some nice Icons via Android Asset Studio.

Customization

Just because we put the tabs at the bottom doesn't mean they are stylized how we want them. There are a few new cross-platform APIs that we can use to add our brands color palette to the new bottom tabs.

Bar Background Color

This proprty, BarBackgroundColor, works across all platforms and sets the background color of the bar :)

Bar Text Color

This proprty, BarTextColor, works across all platforms and sets the text color of the bar :)

Here is me setting them:

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
    android:TabbedPage.ToolbarPlacement="Bottom"
    BarBackgroundColor="#2196F3"
    BarTextColor="White"

BottomTabsWithColor-1

Android Specific Customization

Something that you may have noticed is that our icons are a bit hard to see. That is because on Android you actually have a lot more control over the items inside of each tab.

Bar Item Color

This property, BarItemColor, specifically sets the icon and text color for all of them. So for this you may want to set a slightly faded out color.

Bar Selected Item Color

This property, BarSelectedItemColor, specifically sets the icon and text color for the selected item. So for this we will want to set it to be something bold that will stand out. Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
    android:TabbedPage.ToolbarPlacement="Bottom"
    BarBackgroundColor="#2196F3"
    BarTextColor="White"
    android:TabbedPage.BarItemColor="#66FFFFFF"
    android:TabbedPage.BarSelectedItemColor="White"

BottomTabsWithColor2-1

What is cool about these two properties is that they also work with top tabs so you no longer have to do a custom renderer like I blogged about in the past!

TopTabs-1

One Gotcha

The only gotcha here is that Google turned on "sliding" tabs by default for some reason and has a private API to turn them off.

tabbedpage-toolbar-placement

It isn't too hard to do in code and someone actually got it working in Xamarin.Forms with a custom renderer. I will say it is a bit hacky so I am not sure if they will make this a platform specific in the future, but would be nice and someone already posted a GitHub issue!

Learn More

Check out these amazing docs!

]]>
Xamarin.Forms Android Selected & Unselected Tab Colors https://staging.montemagno.com/xamarin-forms-android-selected-and-unselected-tab-colors/ 598df8f2c121b60019bf2fd5 Tue, 21 Feb 2017 22:51:48 GMT I get a lot of questions about Xamarin.Forms. One of my most popular blogs was about spicing up iOS tabs with selected and unselected tab colors, and since that day developers have been asking about Android. Well, to be honest I was always against adding icons to material tabs in Android, but developers want to do it, so here is how you can, with a Custom Renderer for a Tabbed Page. Here is what it will look like at the end of the day:

Add Icons

First things first, you must set the “Icon” property on each page! As always, I recommend putting all icons into the drawable folders on Android and creating them in Android Asset Studio. 

Custom TabbedPage

Instead of using the default TabbedPage, we will want to create a custom TabbedPage. I called mine “MyTabs”, and there isn’t anything special about it except I use it as my base page in the XAML.

Running the app now should look like:

Android Color Selector

Now, is the fun part. Head over to your Resources folder on Android and add a new folder called color, and then create a new xml file inside of it, which I have called icon_tab.xml. This will be our color selector for each state. There are really only two states, selected and anything else. Here is what mine looks like.

TabbedPage Renderer

Finally, just like we did on iOS we need to add a custom renderer. The goal here is to find the tabs and apply the color selector.

And, that is about it to be honest with you. I hope you enjoy it :)

]]>
TintColor & Selected Tab Images in Xamarin.Forms iOS https://staging.montemagno.com/tintcolor-selectedimage-xamarin-forms-ios/ 598df8f2c121b60019bf2ff5 Thu, 28 Jan 2016 17:56:38 GMT If you have been reading the blog recently then you know that I have been all about iOS on Xamarin.Forms. I love it! I can’t help myself. No more storyboards, no more xibs, and I get to use Grids and StackLayouts! Who would have thought that James Montemagno would be blogging more about iOS then Android on MotzCodes! Well the main reason is that while out of the box Xamarin.Forms iOS apps look pretty darn good there are still a lot of small tweaks that can add that extra polish to your app. I blogged a bit ago about back text on the NavigationBar, and today I am switching over to our good friend the TabItem on the TabbedPage for Xamarin.Forms. Icons, text, and a highlight color when you tap on it! What more could you want! Well reading the Apple Design Guidelines… a bit more.

TintColor

That is right! Tint! I like to have a theme for my apps as far as colors and styles and TintColor play a huge role into how your app looks on iOS. iOS has a really great Appearance Class that helps you set defaults throughout your application that you can use to take your icons from this:

to this:

with just this single line of code in the `FinishedLaunching` of your `AppDelegate`:

UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(118,53,235);

Selected TabItem Image

Another way to spice up your user interface is to have a a completely different image on the selected tab. Usually it fills in and inverts the icon in some way. For example we would want our tabs to look like:

So the first thing is to create those selected images and add them to your Resources folder in your iOS project:

Notice I have tab_about.png that is what my ContentPage.Icon property is set to. I have added in the _selected.png too, which is what we will want to use. For this to work the naming is very important as you will see because all we need to do is create a custom renderer in our iOS project to swap out the SelectedImage on the TabBarItems when our TabbedPage shows up:

public class SelectedTabPageRenderer : TabbedRenderer
{
       public override void ViewWillAppear(bool animated)
        {

            if (TabBar?.Items == null)
                return;

            var tabs = Element as TabbedPage;
            if (tabs != null)
            {
                for (int i = 0; i < TabBar.Items.Length; i++)
                {
                    UpdateItem(TabBar.Items[i],  tabs.Children[i].Icon);
                }
            }

            base.ViewWillAppear(animated);
        }

        void UpdateItem(UITabBarItem item, string icon)
        {
            if (item == null)
                return;
            try
            {
                icon = icon.Replace(".png", "_selected.png");
                if(item?.SelectedImage?.AccessibilityIdentifier == icon)
                    return;
                item.SelectedImage = UIImage.FromBundle(icon);
                item.SelectedImage.AccessibilityIdentifier = icon;
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to set selected icon: " + ex);
            }

        }
}

That’s it! Super crazy simple to make your tabs look about 100% better! Have fun out there.

Looking for Android? Head over to my blog post outlining how to implement it.

]]>