Is there a simple way to minimize the height of the TabWidget without having the labels go out of view?
Not to sure what you mean by this, can you elaborate?
I followed this tutorial on the Xamarin site.
I want the tabs in my application to have a shorter height and not have any icons. If I do not include icons and shorten the height of the tabs in the xml, the label (ie. “Albums”, “Artists”, and “Songs” goes out of view (attached).
How can I fix this?
Ah, okay. That looks like resources issue. I bet what is happening here is that that the images on that page aren't the correct DPI for the device you're running the application on.
The easiest way to create the proper images is to use the Android Asset Studio, in this case we want to use Tab Icons (pre-Android 3.0).
Trying using the drawables in this zip file instead. Just download the file, and extract the contents to the Resources folder in your application. Don't forget to delete the old images.
If you're still having problems, hope over to Xamarin's chat, and ping me there (tom.opgenorth).
I'm not sure you understood my question. I don't want my tabs to have images. I just want the labels ("Artists" "Songs" "Albums").
I want the tabs to have a shorter height, no images, and I want the text on the tabs to be visible. As you can see from my previous post, the text on the tabs is not visible.
Ah, okay. Yes in that case I did misunderstand. What you can do is use a custom view for the tab, instead of the default view that the TabWidget creates. Here is a pretty plain example to get you going:
Add a new layout file called tab_layout.xml to your project with the following XML:
<?xml version="1.0" encoding="utf-8"?>
Add a method to the Activity like this:
private View CreateTabView(string tag)
var tabView = LayoutInflater.Inflate (Resource.Layout.tab_layout, null);
var textView = tabView.FindViewById<TextView> (Resource.Id.tabLabel);
textView.Text = tag;
Then replace each call to SetIndicator to use the custom view, kind of like so:
spec = TabHost.NewTabSpec ("artists");
spec.SetIndicator (CreateTabView ("Artists"));
Now you're application will have a single TextView for each tab. This is a pretty plain example that you'll have to spruce up as you see fit.
Thanks for this. I'll give it a try and let you know how it works.
@topgenorth, it worked out quite nicely. Thanks again!
Cool! Glad it worked out for you. Another option would be to use an ActionBar and fragments, but that's probably best left for another day.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies