Android Action Bar Tabs, Styling the Icon and Text together
android, xamarin, xamarin.android
Solution
My solution isn't perfect, but to move the icons above the text here is what I have so far, which might be able to help you.
TabLayout.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
<TextView
android:id="@+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.cs
void AddTabToActionBar(int labelResourceId, int iconResourceId)
{
var tab = this.ActionBar.NewTab();
tab.SetCustomView(Resource.Layout.Tablayout);
tab.CustomView.FindViewById<ImageView>(Resource.Id.tabImage).SetImageResource(iconResourceId);
tab.CustomView.FindViewById<TextView>(Resource.Id.tabText).SetText(labelResourceId);
tab.TabSelected += TabOnTabSelected;
ActionBar.AddTab(tab);
}
Problem
Firstly, there is the image of my current tab bar What I want is either aligning the images to very left, while keeping the text centered or moving the images on top of the text centered. Here is how I add the texts: ``` var tab = this.ActionBar.NewTab (); tab.SetText (tabText); tab.SetIcon (iconResourceId); ``` Here is my relevant style.xml entries: ``` <style name="Theme.Discover" parent="@android:style/Theme.Holo.Light"> <item name="android:actionBarStyle">@style/MyActionBar</item> <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item> <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item> <item name="android:actionMenuTextColor">#ffffff</item> <item name="android:windowBackground">@drawable/bg</item> </style> <style name="MyActionBarTabStyle" parent="@android:style/Widget.Holo.Light.ActionBar.TabView"> <item name="android:background">@drawable/action_tab_selector</item> </style> <!-- ActionBar tabs text styles --> <style name="MyActionBarTabText" parent="@android:style/Widget.Holo.ActionBar.TabText"> <item name="android:textColor">#ffffff</item> </style> ``` I can understand java code too so if you are not familiar with Xamarin, I still appreciate the java examples&answers.