Android: modify background of Tab header.
I want to add selecto开发者_如何学Pythonr to tab header (not tab body), but without results. May be someone has an example?
Easy way to do it:
Create custom layout:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dip" android:layout_height="64dip" android:layout_weight="1" android:orientation="vertical" android:background="@drawable/tab_indicator" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:paddingTop="7dip" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" style="?android:attr/tabWidgetStyle" android:paddingBottom="5dip" /> </RelativeLayout>
Add tabs using this layout:
private void addTab(String text, int drawable) { TabHost.TabSpec spec = mTabHost.newTabSpec(text); View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); TextView title = (TextView) tabIndicator.findViewById(R.id.title); title.setText(text); ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); icon.setImageResource(drawable); spec.setIndicator(tabIndicator); mTabHost.addTab(spec.setContent(this)); }
精彩评论