0

In my tabactivity, I display icon that I get from the database, by creating an ImageView and passsing this to the setIndicator method. I have only one image for each tab, so I was wondering if there is way to just change the color of the image alone (as opposed to changing the tab's color) when a tab is selected? Also is it possible to hide the gray line that is being drawn at the bottom of the tabs when a tab is selected? Any help is appreciated..thanks

anddeveloper
  • 1
  • 1
  • 1

1 Answers1

3

Hiding gray line:

yourTabWidget.setStripEnabled(false);

Setting custom image per tab state:

tabitemicon.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/orange"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/white" />
</selector>

Java code:

tabHost = getTabHost():
tabHost.newTabSpec("test").setIndicator("My Tab Title",
                          res.getDrawable(R.drawable.tabitemicon))
                      .setContent(someIntent);
azharb
  • 979
  • 6
  • 15
  • Thanks for the quick reply. I forgot to mention that I'm building the project against Android2.1 and I beleive "tabStripEnabled" was introduced in 2.2. Is there a way to accomplish this in 2.1? Also I get my icon from the database and create an imageview on the fly and pass it to the setIndicator(). I'm assuming the code you provided will work only if I get the image from the drawable folder? – anddeveloper Apr 06 '11 at 19:30
  • As far as hiding the gray line goes, if you can't hide it then I would recommend you somehow include it in your design. As in make the background of your tab to be the strip background and then include a border in your tab logo to indicate separation. Here's a link to a previously answered question to declare a selector programatically. Hope that helps. http://stackoverflow.com/questions/4697528/replace-selector-images-programmatically/4697794#4697794 – azharb Apr 06 '11 at 19:36