0

I have created a tab in my app. Now the thing is that when I set the background color of my tab to white it's working but only grey color underline still appears so can anyone tell me how can I remove that line?

I am sending my code and snapshot of where the underline arise.

Code for XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:background="#FFFFFF">

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="#FFFFFF">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"/>
        </LinearLayout>
    </TabHost>
</LinearLayout>

Code for java:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Resources res = getResources(); 
    TabHost MainTabHost = getTabHost();  
    TabHost.TabSpec spec; 
    Intent intent; 
    intent = new Intent().setClass(this, ContactListForm.class);

    spec = MainTabHost.newTabSpec("Contacts").setIndicator("Contacts",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    MainTabHost.addTab(spec);

    intent = new Intent().setClass(this, CallDialerForm.class);
    spec = MainTabHost.newTabSpec("Call").setIndicator("Call",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    MainTabHost.addTab(spec);

    intent = new Intent().setClass(this, MyInfoForm.class);
    spec = MainTabHost.newTabSpec("My Info").setIndicator("MyInfo",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    MainTabHost.addTab(spec);

    MainTabHost.setCurrentTab(0);
   for (int j = 0; j < MainTabHost.getTabWidget().getChildCount(); j++) 
    {
        MainTabHost.getTabWidget().getChildAt(j).setBackgroundColor(Color.parseColor("#FFFFFF"));
    }

}

Snapshot:

Snapshot

iknow
  • 8,358
  • 12
  • 41
  • 68
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • I think that is the back drop of the tab host and how the tabs work.. you may be able to set it to null or transparent or white even – O'Mutt Jun 29 '11 at 13:24
  • how that can be done..can you please show it – AndroidDev Jun 29 '11 at 13:35
  • `MyTabHost.setBackgroundColor(#000000);` I would suggest that as an answer but i'm not 100% sure... just a guess on how i understand tabhosts and tabs working from past exp. – O'Mutt Jun 29 '11 at 13:38
  • check this **previously ask question** [Stackoverflow - Get rid of the line under tabwidget](http://stackoverflow.com/questions/3511596/get-rid-of-the-line-under-tabwidget) – O'Mutt Jun 29 '11 at 14:12

2 Answers2

1

Use this in your code where you setup tabs. Mind you it is supported only from SDK 8 onwards.

if(7 < Build.VERSION.SDK_INT){
    tabHost.getTabWidget().setStripEnabled(false);
 }
PravinCG
  • 7,688
  • 3
  • 30
  • 55
  • yeh its working thanks..but text appear only when i am not clicking the tabs..so what should i do for make the text appear even after clicking the text – AndroidDev Jun 29 '11 at 14:28
  • The color of the text is white and since your background is also white, you cannot see it. Change the color of text when clicked to black and you can see it. – PravinCG Jun 29 '11 at 14:30
  • Actually i havent found any function for that..can you please check that – AndroidDev Jun 29 '11 at 14:34
  • ((TextView)tabwidget.getChildAt(0).findViewById(android.R.id.title)).setTextColor(0xFF000000); – PravinCG Jun 29 '11 at 14:35
  • its show error in tabwidget and setTextColor "tabwidgets and settextcolor cannot be resove" – AndroidDev Jun 29 '11 at 14:41
  • Use this to get the TabWidget tabHost.getTabWidget() and paste the code so that I can check for syntax errors. – PravinCG Jun 29 '11 at 14:45
0

I was also same type of problem but i have removed it using the fallowing blow given code

        tabHost = getTabHost(); // The activity TabHost
    tabHost.setOnTabChangedListener(this);
    Resources res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
    TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
    TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
    TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
    TabSpec fifthTabSpec = tabHost.newTabSpec("tid5");

    viewCache[0] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[1] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[2] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[3] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[4] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);

    firstTabSpec.setIndicator(viewCache[0]);
    secondTabSpec.setIndicator(viewCache[1]);
    thirdTabSpec.setIndicator(viewCache[2]);
    fourthTabSpec.setIndicator(viewCache[3]);
    fifthTabSpec.setIndicator(viewCache[4]);

    firstTabSpec.setContent(new Intent(this, HomeTabActivityGroup.class));
    secondTabSpec
            .setContent(new Intent(this, ProfileTabActivityGroup.class));
    thirdTabSpec.setContent(new Intent(this,
            NotificationTabActivityGroup.class));
    fourthTabSpec.setContent(new Intent(this,
            FavoritesTabActivityGroup.class));
    fifthTabSpec
            .setContent(new Intent(this, MoreTabActivityGroupNew.class));

    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);
    tabHost.addTab(thirdTabSpec);
    tabHost.addTab(fourthTabSpec);
    tabHost.addTab(fifthTabSpec);

    currentTabvalue = tabHost.getCurrentTab();
    C2DMessaging.register(TennisAppActivity.mContext,
            "racquetester@gmail.com");
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {

        // tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7392B5"));
        switch (i) {
        case 0:
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.home);
            break;
        case 1:
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.profile);
            break;
        case 2:
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.notifications);
            break;
        case 3:
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.fav);
            break;
        case 4:
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.more);
            break;
        }
    }

//*************************************************** it is the xml file use for it.

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"
  xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
  <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content"              android:layout_height="50dip"></ImageView>

I hope it is help full to you.

DynamicMind
  • 4,240
  • 1
  • 26
  • 43