Focus on IT Recommend

Home > Xamarin.Forms Android Tabbar custom with Icon and Text

Xamarin.Forms Android Tabbar custom with Icon and Text

2020腾讯云“6.18”活动开始了!!!(巨大优惠重现!4核8G,5M带宽 1999元/3年),



I have checked and implemented with following links: Android Action Bar Tabs, Styling the Icon and Text together And now I can see image above text. I want to increase the height of tabbar so that the icon have larger size. I also checked How to change action bar size & And I tried to implement AppCompatActivity in my Xamarin.Forms project. At first, android activity was derived from global::Xamarin.Forms.Platform.Android.FormsApplicationActivity and now it is converted to global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity. And the custom Renderer was implemented for TabbedPage. I know it must be converted to TabbedPageRender for AppCompatActivity. So I updated the renderer too. But now the custom renderer is not being called. And I can't change the height of Tabbar that is placed in ActionBar for AppCompatActivity. Let me know what I implemented wrong. Thank you.

android android-actionbar xamarin.forms tabpage appcompat-v7-r22.1
  this question
edited Apr 6 '16 at 14:24 Mihriban Minaz 2,311 2 19 46 asked Apr 6 '16 at 12:40 Bill Frank 1 1      Questions seeking debugging help ( "why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example –  Dalija Prasnikar Apr 6 '16 at 12:41


1 Answers

If you have code, please post it.

  1. In your activity, check if you have

    FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar; FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;

in OnCreate method, also you need toolbar.xml and tabs.xml in /resources/layout folder.

  1. In your renderer class, make sure you add

    [assembly: ExportRenderer(typeof (YourTabbedPage), typeof (YourTabbedPageRenderer))]

    Recommend:android - How to change the TableSection text color with a custom renderer - Xamarin.Forms C#

    eight = 60, Root = new TableRoot { firstTableSection, secondTableSection, thirdTableSection, }}var firstTableSection = new TableSection("First"){ // Cells}var firstTableSection = new TableSection("First"){ //

  2. TabbedPageRenderer doesn't expose tablayout for you, thus reflection needed

    public class YourTabbedPageRenderer : TabbedPageRenderer { private TabLayout _myTabLayout;

    protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        var fieldInfo = typeof (TabbedPageRenderer).GetField("_tabLayout", BindingFlags.Instance | BindingFlags.NonPublic);
        System.Diagnostics.Debug.Assert(fieldInfo != null, "fieldInfo != null");
        _myTabLayout = (TabLayout) fieldInfo.GetValue(this);
        // Uncomment to Disable scrolling
        //var propInfo = typeof (TabbedPageRenderer).GetProperty("UseAnimations", BindingFlags.Instance | BindingFlags.NonPublic);
        //propInfo.SetValue(this, false);
        if (e.OldElement != null)
        if (e.NewElement != null)
            if (_myTabLayout.TabCount != this.Element.Children.Count)
            for (int index = 0; index < this.Element.Children.Count; ++index)
                FileImageSource icon = this.Element.Children[index].Icon;
                if (string.IsNullOrEmpty(icon))
                var imageView = new AppCompatImageView(this.Context);
                imageView.SetPadding(4, 4, 4, 4);
                var drawable = ResourceManager.GetDrawableByName(icon.File);


  this answer
edited Apr 7 '16 at 2:22 answered Apr 7 '16 at 2:15 Bonelol 246 1 12


Recommend:android - Adjust resize does not work in API 22 with AppCompat on Xamarin.Forms

method for dealing with the soft keyboard. I do this by setting it in OnCreate like this: [Activity(Label = "TestWhite.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Or


------splitte line----------------------------