我想更改tabwidget
中選定選項卡的高度,如下圖所示。安卓更改tabwidget中選定選項卡的高度
我使用的方法:我使用了兩個圖像的第一個圖像有透明的部分在上面,第二個是完整的圖像,在選項卡上我改變了第一個圖像與第二個。但是這種方法在所有設備中都不起作用。我們必須創建具有相同高度的圖像,並將其轉換爲每個9個補丁。
該圖顯示了我確切需要的。
TabHost.TabSpec spec = mTabHost.newTabSpec(AppConstants.TAB_A);
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return findViewById(R.id.realtabcontent);
}
});
spec.setIndicator(createTabView(R.drawable.hometabselection));//style applied here on each tab
mTabHost.addTab(spec);
spec = mTabHost.newTabSpec(AppConstants.TAB_B);
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return findViewById(R.id.realtabcontent);
}
});
spec.setIndicator(createTabView(R.drawable.realtabselection));
mTabHost.addTab(spec);
spec = mTabHost.newTabSpec(AppConstants.TAB_C);
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return findViewById(R.id.realtabcontent);
}
});
spec.setIndicator(createTabView(R.drawable.topnewwsselection));
mTabHost.addTab(spec);
spec = mTabHost.newTabSpec(AppConstants.TAB_D);
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return findViewById(R.id.realtabcontent);
}
});
spec.setIndicator(createTabView(R.drawable.treadingselection));
mTabHost.addTab(spec);
hometabselection.xml //在繪製其用於所有不同的標籤選擇
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_selected="true"
android:drawable="@drawable/homeselected" />//full image
<item
android:state_selected="false"
android:drawable="@drawable/homenormal" />//image with some portion transparent on top of that
</selector>
佈局
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="@dimen/fr_layout_width"
android:layout_height="@dimen/fr_layout_height"
android:layout_weight="0" />
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="@dimen/fr_layout_height"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="@dimen/hdpi_tab_layout_height"
android:layout_weight="0"
android:divider="@drawable/tab_bg"
android:background="@android:color/transparent"
android:dividerPadding="@dimen/tab_divider_padding"
android:orientation="horizontal" />
</LinearLayout>
</TabHost>
你能提供你使用的代碼嗎? – nKn
@NKN我更新了代碼。 –
您可以添加如何動態設置其他可繪製的?我想你正在做一個onTabChangedListener。 – nKn