Question

I'm using android 2.3.3. I've created two tab indicators using custom layout, but there is always a black line between them. Below is the result screen.enter image description here

I want to delete or hide the two black lines. I think those two are tab dividers, so I using

tabHost.getTabWidget().setDividerDrawable(null)

to delete divider, but nothing happens. Below is my code:

package com.intasect.htfutures.activities;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;

import com.intasect.core.tab.TabMainActivity;
import com.intasect.htfutures.activities.competitionpk.PkActivityGroup;
import com.intasect.htfutures.activities.home.HomeActivityGroup;
import com.intasect.htfutures.utils.Const;

public class MainActivity extends TabMainActivity {

    int currentTabId = 0;
    public static TabHost tabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tabHost = getTabHost();
        final TabWidget tabwidges = tabHost.getTabWidget();
        Intent intent;
        // 首页
        intent = new Intent(this, HomeActivityGroup.class);
        tabHost.addTab(tabHost.newTabSpec(String.valueOf(TAB_ID_HOME))
                .setIndicator(createView(TAB_ID_HOME, true)).setContent(intent));
        // 业绩PK
        intent = new Intent(this, PkActivityGroup.class);
        tabHost.addTab(tabHost.newTabSpec(String.valueOf(TAB_ID_PK))
                .setIndicator(createView(TAB_ID_PK)).setContent(intent));

        // 设置
//      intent = new Intent(this, SettingsActivityGroup.class);
//      tabHost.addTab(tabHost.newTabSpec(String.valueOf(TAB_ID_SETTINGS))
//              .setIndicator(createView(TAB_ID_SETTINGS)).setContent(intent));

        /*
         * 设置tab监听事件,改变背景颜色
         */
        tabHost.setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {
                currentTabId = tabHost.getCurrentTab();
                chooseTab(tabwidges, currentTabId);
            }

        });

        tabHost.setCurrentTab(currentTabId);

        Const.initApp();
    }

    private static final int TAB_ID_HOME = 0;
    private static final int TAB_ID_PK = 1;
//  private static final int TAB_ID_SETTINGS = 2;
    private static final int TOTAL_TAB_COUNT = 2;
    private static final int[] IMAGE_IDS = { R.drawable.btn_tab_home,
            R.drawable.btn_tab_home_selected, R.drawable.btn_tab_query,
            R.drawable.btn_tab_query_selected };

    private View createView(int tabId) {
        return createView(tabId, false);
    }

    private View createView(int tabId, boolean choosed) {
        ImageButton image = new ImageButton(this);
        changeTabImage(image, tabId, choosed);
        return image;
    }

    private void changeTabImage(ImageButton image, int tabId, boolean choosed) {

        image.setImageResource(choosed ? IMAGE_IDS[tabId * 2 + 1]
                : IMAGE_IDS[tabId * 2]);
        image.setBackgroundColor(choosed ? Color.WHITE : getResources().getColor(R.color.tab_item_gray));
    }

    private void chooseTab(TabWidget tabwidges, int tabId) {
        resetAllTabToUnselected(tabwidges);
        ImageButton image = (ImageButton) tabwidges.getChildAt(tabId);
        changeTabImage(image, tabId, true);
    }

    private void resetAllTabToUnselected(TabWidget tabwidges) {
        for (int i = 0; i < TOTAL_TAB_COUNT; i++) {
            ImageButton image = (ImageButton) tabwidges.getChildAt(i);
            changeTabImage(image, i, false);
        }
    }
}

my layout xml:

<?xml version="1.0" encoding="utf-8"?>
<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="@android:color/white" >

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingBottom="66dip" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_margin="0dp"
        android:divider="@null"
        android:fadingEdge="none"
        android:fadingEdgeLength="0dp"
        android:padding="0dp"
        android:tabStripEnabled="false" />

</TabHost>

I've tried many ways to delete those two lines, but there is no miracle. How can I remove them?

Was it helpful?

Solution 2

add these lines in xml for Tabhost|TabWidget

 android:divider="@null"
 android:fadingEdge="none" 
 android:fadingEdgeLength="0dp" 

OTHER TIPS

i figured out by myself.i'm really sorry to ask such a stupid question.that black line is not divider,it is on my picture.i delete that line in my picture,every thing goes perfect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top