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 & https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/. 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.
Asked
Active
Viewed 3,130 times
-2
-
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](http://stackoverflow.com/help/mcve) – Dalija Prasnikar Apr 06 '16 at 12:41
1 Answers
1
If you have code, please post it.
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.
In your renderer class, make sure you add
[assembly: ExportRenderer(typeof (YourTabbedPage), typeof (YourTabbedPageRenderer))]
TabbedPageRenderer doesn't expose tablayout for you, thus reflection needed
public class YourTabbedPageRenderer : TabbedPageRenderer { private TabLayout _myTabLayout;
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e) { base.OnElementChanged(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) return; for (int index = 0; index < this.Element.Children.Count; ++index) { _myTabLayout.GetTabAt(index).SetText(""); FileImageSource icon = this.Element.Children[index].Icon; if (string.IsNullOrEmpty(icon)) continue; var imageView = new AppCompatImageView(this.Context); imageView.SetPadding(4, 4, 4, 4); var drawable = ResourceManager.GetDrawableByName(icon.File); imageView.SetImageResource(drawable); _myTabLayout.GetTabAt(index).SetCustomView(imageView); } _myTabLayout.GetTabAt(0).Select(); } }
}

Bonelol
- 526
- 6
- 13