與視圖創建標籤:
final TabHost tabs = getTabHost();
tabs.setup();
final TabHost.TabSpec spec = tabs.newTabSpec("tag");
spec.setIndicator(View.inflate(this, R.layout.tab_view, null));
tabs.addTab(spec);
定義你的選擇
<?xml version="1.0" encoding="utf-8"?>
<item android:state_pressed="true" >
<shape>
<gradient
android:endColor="#bbb"
android:centerColor="#999"
android:startColor="#ddd"
android:angle="270" />
<stroke
android:width="3dp" />
<corners
android:topLeftRadius="10dp"
android:bottomRightRadius="0.1dp"
android:bottomLeftRadius="0.1dp"
android:topRightRadius="10dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_selected="true" >
<shape>
<gradient
android:endColor="#888"
android:centerColor="#777"
android:startColor="#999"
android:angle="270" />
<stroke
android:width="3dp" />
<corners
android:topLeftRadius="10dp"
android:bottomRightRadius="0.1dp"
android:bottomLeftRadius="0.1dp"
android:topRightRadius="10dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#eee"
android:centerColor="#aaa"
android:endColor="#ccc"
android:angle="270" />
<stroke
android:width="3dp" />
<corners
android:topLeftRadius="10dp"
android:bottomRightRadius="0.1dp"
android:bottomLeftRadius="0.1dp"
android:topRightRadius="10dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
您選擇作爲背景繪製添加到您的標籤視圖
<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/tab_width"
android:layout_height="fill_parent"
android:background="@xml/tabs_background"/>
"@dimen/tab_width"
是您在dp,像素或smthn中的標籤寬度。
給logcat中的細節,並給上你得到你所定義的error.Have行color.xml中的透明顏色? – 2011-04-29 13:43:00