2013-05-05 50 views
0

在我的Android應用程序中,我有5個標籤欄中的標籤欄。如果我爲選項卡名稱設置了5個以上的字母,如果從右向左選擇,則該單詞開始動畫。我想設置一個標籤欄「圖標」+「文本」,以便在我選擇一個標籤之前,我會看到一個圖標,但是如果選中它,它會將文本動畫化。就像它與長文本一樣。標籤欄圖標在Android上的文字動畫

setIndicator(drawable + string)

這是我的代碼有:

private void initialiseTabHost(Bundle args) { 
    mTabHost = (TabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(); 
    TabInfo tabInfo = null; 
    TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator(getResources().getDrawable(R.drawable.social_group), "SomeText"), (tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("SomeText"), (tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("SomeText"), (tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab4").setIndicator("SomeText"), (tabInfo = new TabInfo("Tab4", Tab4Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab5").setIndicator("SomeText"), (tabInfo = new TabInfo("Tab5", Tab5Fragment.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    // Default to first tab 
    this.onTabChanged("Tab1"); 
    // 
    mTabHost.setOnTabChangedListener(this); 
} 

但代碼不會運行,和Im收到此錯誤:

The method setIndicator(CharSequence, Drawable) in the type TabHost.TabSpec is not applicable for the arguments (Drawable, String) 

任何想法?我如何解決它?

P.S runing android 4.0.4使用片段設置標籤。

如果我把它像這樣:

TabActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator(getResources().getDrawable(R.drawable.social_group) + "SomeText"), (tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args))); 
     this.mapTabInfo.put(tabInfo.tag, tabInfo); 

我碰到一個 「文本」 + 「文本」,insted的 「圖標」 + 「文本」 :(

+0

動畫在標籤欄的文本是它內置的行爲。據我所知,你無法控制它的動畫。但是,是的,你可以設置圖標+文字的標籤欄。 – GrIsHu 2013-05-06 12:56:50

+0

請發佈您的logcat錯誤。 – GrIsHu 2013-05-06 13:02:07

+0

Hi GrIsHu,在setIndicator下沒有log cat eror紅色underilning:類型TabHost.TabSpec中的方法setIndicator(CharSequence,Drawable)不適用於參數(Drawable,String)。但我會嘗試你的答案,並讓你知道它是否工作))) – user1810991 2013-05-06 22:20:30

回答

0

您可以設置「圖標的+文字」,在標籤欄由如下其資源設置方法。

m_spec =m_tabHost.newTabSpec("Cat").setIndicator(getString(R.string.category), 
    m_res.getDrawable(R.drawable.ic_tabcategory)).setContent(m_mainMenuIntent); 
    m_tabHost.addTab(m_spec); 
+0

謝謝,但我在4.0.4獲得相同的結果。在較低版本中,我得到一個圖標+文字))) – user1810991 2013-05-08 22:28:25