【问题标题】:Text on Tab of TabViewTabView 选项卡上的文本
【发布时间】:2011-04-21 09:25:18
【问题描述】:

我想将文本放在我的应用程序的每个选项卡上,并且还想改变它的默认颜色。 . .怎么可能?

【问题讨论】:

  • 请你停止标记你的问题 android-ndk,这很烦人。它们与 NDK没有任何关系。

标签: android android-emulator android-layout android-widget


【解决方案1】:

我在我的一个应用程序中为选项卡定义了自定义样式。

类似于:

(注意:在styles.xml文件中定义这个样式)

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="@android:style/Theme.Light">
        <item name="android:tabWidgetStyle">@style/LightTabWidget</item>
    </style>

    <style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
        <!-- set textColor to red, so you can verify that it applied. -->
        <!-- <item name="android:textColor">#f00</item>  -->
        <item name="android:textSize">12px</item>
        <item name="android:textColor">#1E90FF</item>
    </style>

</resources>

并在 AndroidManifest.xml 文件中的应用程序标签中给出这个主题:

 <application android:icon="@drawable/icon" 
                 android:label="@string/app_name"
                 android:theme="@style/MyTheme">

更新:

您仍然已经完成了问题的解决方案,让我提出一个同样有效的示例:how to change the color of the tabs indicator text in android?

【讨论】:

  • 我把 styles.xml 文件放在哪里。 . . ??
  • @Shreyash 位于 Values 文件夹中。
  • @Shreyash 检查我更新的答案,并将此代码放在 values 文件夹中的 styles.xml 中。
  • 现在文件没有错误但对我当前的标签文本没有任何影响。 . .应该是什么问题?
  • @Shreyash 很高兴得到您的快速回复。但是遇到问题后,你做了什么来解决问题?
【解决方案2】:

类似的东西:

private View createTabIndicator(String text) {
    Button button = new Button(this);
    button.setBackgroundResource(R.drawable.tab);
    button.setText(text);
    button.setTextColor(Color.WHITE);
    button.setGravity(Gravity.CENTER);
    return button;
}
...
getTabHost().addTab(getTabHost().newTabSpec("name").setIndicator(createTabIndicator("name")).setContent(data));

【讨论】:

    【解决方案3】:

    这是一个这样做的例子,

    TabSpec pecHome = tabHost.newTabSpec("Home").setIndicator("Home",
                    res.getDrawable(R.drawable.home)).setContent(intentHome);
    tabHost.addTab(specHome);
    

    这里 ssetIndicator 将使您能够显示文本。

    仅此而已 最好的问候 阿努普

    【讨论】:

    • 谢谢,但我想改变它的颜色。 . .我想更改指标的颜色。 .
    • 我认为这会帮助你 tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); //未选中
    • 请给我一些更详细的代码。 .因为我没有让你正确。 . .
    • “getTabWidget()”是现成的方法吗?还是自定义函数?
    猜你喜欢
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 2015-01-19
    • 2012-12-14
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多