вы можете указать свой макет с помощью tabSpec:
Здесь у вас есть addTab в вашем адаптере
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args)
{
tabSpec.setContent(new DummyTabFactory(mContext));
String tag = tabSpec.getTag();
TabInfo info = new TabInfo(tag, clss, args);
mTabs.add(info);
mTabHost.addTab(tabSpec);
notifyDataSetChanged();
}
и, прежде чем заполнить вкладку содержимым (обычно в onCreate), вы можете написать свою собственную функцию
private static View prepareTabView(Context context, String text, int drawable)
{
View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
((TextView) view.findViewById(R.id.tabTitle)).setText(text);
((ImageView) view.findViewById(R.id.tabImage)).setImageResource(drawable);
return view;
}
public static void addTab(TabsAdapter adapter, TabHost host, String title, String tag, int drawable, Class cl)
{
TabHost.TabSpec spec = host.newTabSpec(tag);
View view = prepareTabView(host.getContext(), title, drawable);
spec.setIndicator(view);
adapter.addTab(spec, cl,null);
}
и теперь вы можете заполнить свой tabHost собственным addTab, который использует addTab в адаптере:
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
mViewPager = (ViewPager) findViewById(R.id.pager);
mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager, getSupportFragmentManager());
addTab(mTabsAdapter, mTabHost, getString(R.string.title1), CONST, R.drawable.tab_drawable1, Fragment1.class);
addTab(mTabsAdapter, mTabHost, getString(R.string.title1), CONST2, R.drawable.tab_formula_image_selector, Fragment2.class);
в этом примере у вас есть R.layout.tab_layout с рисованием, фоном, текстом и т. Д. ...:
R.layout.tab_layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top" android:background="@drawable/tabbg">
<TextView
android:id="@+id/tabTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:text="TextView"
android:textColor="@color/tabtextcolor"
android:textSize="12sp" android:layout_alignParentBottom="true"/>
<ImageView
android:id="@+id/tabImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp" android:layout_above="@id/tabTitle" android:layout_centerHorizontal="true"/>
</RelativeLayout>
с этим примером у вас будет что-то вроде этого: