Hello,
Welcome to our Microsoft Q&A platform!
the active font size will be larger than that is not active how to make the two menu font size equal?
You can use Shell custom renderers to change tab bar text size and change icon.
Please refer to the following code:
1.In android, create MyShellRenderer
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace shellicon.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new CustomBottomNavAppearance();
}
}
public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(BottomNavigationView bottomView)
{
throw new NotImplementedException();
}
public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
var instance = MainActivity.mactivity;
int width = instance.width;
if(width>??)
{
var bottomNavMenuView = bottomView.GetChildAt(0) as BottomNavigationMenuView;
for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
{
var item = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
var itemicon = item.GetChildAt(0);
var itemTitle = item.GetChildAt(1);
var IconImageView = (ImageView)itemicon;
var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));
IconImageView.SetImageResource(Resource.Drawable.check);
smallTextView.TextSize = 18;
largeTextView.TextSize = 18;
}
}
}
}
2.Getting current screen size in Mainactivity.cs
:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public static MainActivity mactivity;
public int width { get; set; }
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
var metrics = Resources.DisplayMetrics;
width = metrics.WidthPixels;
mactivity = this;
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Best Regards,
Jessie Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.