
Я использовал следующий код для генерации этого результата.Я установил четвертую вкладку кликабельной ложь.Только кнопка внутри вкладки будет кликабельной.Так что создается впечатление, что это не вкладка.Надеюсь, это поможет.
Активность:
public class MainActivity extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.item_seperator);
setupTab(new TextView(this), "Month");
setupTab(new TextView(this), "Week");
setupTab(new TextView(this), "Day");
final View view = new Button(this);
View tabview = LayoutInflater.from(this).inflate(
R.layout.button_tabs_bg, null);
Button button = (Button) tabview.findViewById(R.id.tabsButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button click",
Toast.LENGTH_SHORT).show();
}
});
TabSpec setContent = mTabHost.newTabSpec("").setIndicator(tabview)
.setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
mTabHost.getTabWidget().getChildTabViewAt(3).setEnabled(false);
}
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
.setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context)
.inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
tab_bg_selector.xml
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@color/tablight" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@color/tabdark" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:drawable="@color/tablight" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@color/tablight" />
tabs_bg.xml
<TextView
android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@android:color/white"
android:textSize="15dip" />
button_tabs_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/buttontab"
android:padding="10dip" android:gravity="center" android:orientation="vertical">
<Button
android:id="@+id/tabsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:textColor="@android:color/black"
android:textSize="15dip" />
</LinearLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="tabdark">#333333</color>
<color name="tablight">#999999</color>
<color name="buttontab">#999966</color>
</resources>