0

在我的 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);

我得到“文本”+“文本”,插入“图标”+“文本”:(

4

1 回答 1

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);
于 2013-05-06T12:59:19.297 回答