これを提供する
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
次に、tab_unselected.xml に書き込みます
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ccc"/>
</shape>
& tab_selected.xml の場合
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ccc"/>
</shape>
背景として、画像とテキストビューのレイアウトファイルを作成するか、必要なものは何でも
<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"
android:padding="5dp">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
<TextView android:id="@+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
style="?android:attr/tabWidgetStyle"
/>
メインタブファイルを次のように変更します
oncreate に setTabs() メソッドを配置します。
private void setTabs() {
// TODO Auto-generated method stub
tabHost = getTabHost();
tabHost.getTabWidget().setDividerDrawable(R.drawable.line);
intent = new Intent(this, class1.class);
addTab(1,intent,"tab1");
intent=new Intent(this,class2.class);
addTab(2,intent,"tab2");
intent=new Intent(this,class3.class);
addTab(3,intent,"tab3");
}
今 addTab メソッド
private void addTab(int labelId, Intent intent, String tabName) {
// TODO Auto-generated method stub
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator =LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title1);
title.setTextSize(40);
title.setText(tabName);
ImageView imageView=(ImageView)tabIndicator.findViewById(R.id.icon);
imageView.setImageResource(R.drawable.aries);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
必要なすべてのコードを入力したと思います。