2013-05-05 18 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