1) - 創建名爲report_tabs.xml或者你喜歡的任何名稱的佈局文件。
在report_tabs使用此代碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_tabsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_selector"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="@+id/img_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="3dp"
/>
</LinearLayout>
2) - 和您的活動使用下面的代碼。
Intent intent;
tabhost = getTabHost();
TabHost.TabSpec tabspec;
intent = new Intent().setClass(getApplicationContext(),xxxxx.class);
tabspec = tabhost.newTabSpec("First");
view = LayoutInflater.from(this).inflate(R.layout.report_tabs,
tabhost.getTabWidget(), false);
imgtabF = (ImageView) view.findViewById(R.id.img_icon);
imgtabF.setBackgroundResource(R.drawable.tab_icon_selector);
tabspec.setIndicator(view);
tabspec.setContent(intent);
tabhost.addTab(tabspec);
3) - 創建繪製與名tab_icon_selector文件改變在選項卡中單擊該圖標是這樣的: -
<?xml version="1.0" encoding="utf-8"?>
<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/medical_icon_unselect"
/>
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/medical_icon_sel" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false" android:drawable="@drawable/medical_icon_sel" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/medical_icon_sel" />
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@android:color/transparent"/>
</selector>
現在,您可以創建自定義標籤欄和你的形象圖標會在標籤的中心。
感謝您的回覆 – vaibvorld