【发布时间】:2013-05-05 00:19:20
【问题描述】:
在我的 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)
有什么想法吗?我该如何解决?
P.S 运行 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);
我得到“文本”+“文本”,插入“图标”+“文本”:(
【问题讨论】:
-
标签栏中的文本动画是其内置行为。 AFAIK 你无法控制它的动画。但是是的,您可以在标签栏中设置图标 + 文本。
-
请发布您的 logcat 错误。
-
嗨,GrIsHu,没有日志错误,只是在 setIndicator 下出现红色下划线:TabHost.TabSpec 类型中的方法 setIndicator(CharSequence, Drawable) 不适用于参数(Drawable,String)。但我会尝试你的答案,让你知道它是否有效)))
标签: android tabs android-widget icons android-tabhost