在我的 Android 应用程序中,我在标签栏中有 5 个标签。如果我为选项卡名称设置了 5 个以上的字母,则如果从右到左选择,则该单词开始动画。我想设置一个标签栏“图标”+“文本”,这样在我选择一个标签之前我会看到一个图标,但如果选择它,它会动画成文本。就像它与长文本一样。
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);
}
但是代码不会运行,我得到这个错误:
The method setIndicator(CharSequence, Drawable) in the type TabHost.TabSpec is not applicable for the arguments (Drawable, String)
有任何想法吗?我该如何解决?
PS 运行 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);
我得到“文本”+“文本”,插入“图标”+“文本”:(