我使用的是android 2.3.3。我使用自定义布局创建了两个制表符指示符,但它们之间始终存在黑线。以下是结果屏幕。
我想删除或隐藏两条黑线。我认为这两个是tab分隔符,所以我使用
tabHost.getTabWidget()。setDividerDrawable(空)
删除分隔符,但没有任何反应。 以下是我的代码:
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);
}
}
}
我的布局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>
我尝试过很多方法来删除这两行,但没有奇迹。我该如何删除它们?
答案 0 :(得分:1)
答案 1 :(得分:0)
在xml中为Tabhost | TabWidget
添加这些行 android:divider="@null"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"