0
我想改變圖標時點擊tabhost改變圖標tabhost安卓
下面是源代碼
private void setTabs() {
addTab("Home", TabHome.class, R.drawable.home);
addTab("Performers", TabPerformers.class, R.drawable.performers);
addTab("Tickets", TabTickets.class, R.drawable.tickets);
addTab("Info", TabInfo.class, R.drawable.info);
}
private void addTab(String labelId, Class<?> c, int drawableId) {
tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
我想改變標籤的圖標時,該用戶按tab我用下面tabhost事件
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("tabHome")) {
但不能成功
也有tab_indicater.xml文件但只有背景將是不改變的圖標
低於是XML代碼
<?xml version="1.0" encoding="utf-8"?>
<!-- Non focused states -->
<item android:drawable="@drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
<!-- Pressed -->
<item android:drawable="@drawable/tab_bg_selector" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="@drawable/tab_press" android:state_pressed="true"/>
以下
的屏幕截圖
當我們點擊任何一個選項卡上的圖標應該是喜歡這裏的變化就必須變爲橙色..
任何機構可以幫我...
但在這也是你怎麼能區分這個圖標是這個標籤,該圖標是該標籤? – 2013-05-15 09:52:36
簡單,爲不同的標籤使用不同的繪圖:) – iceman 2013-05-17 04:29:19
謝謝iceman :)我會試試:) – 2013-05-17 10:34:02