如何更改android中tabhost的字体大小

发布于 2024-11-03 03:13:22 字数 41 浏览 1 评论 0原文

如何更改选项卡的字体大小?我为选项卡扩展了 TabActivity。

How can the font size of the tabs be changed? I extend TabActivity for the tabs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

反目相谮 2024-11-10 03:13:22

您可以定义主题,使用样式来实现此目的:

首先,在 res/values/styles.xml 中为您的 Activity 创建主题(名称:CustomTheme

<style name="CustomTheme" parent="@android:style/Theme">
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" 
    parent="@android:style/TextAppearance.Widget.TabWidget">
    <item name="android:textSize">20sp</item>
    <item name="android:textStyle">bold</item>
</style>

然后在您的 androidManifest.xml 中为您的 TabActivity 或包含 TabWidgetActivity 指定上述主题code>:

<activity android:name="MyTabActivity" android:theme="@style/CustomTheme">

这将为您提供您想要的输出(当然您应该根据您的喜好更改大小和样式)。

You can define themes, use styles to achieve this:

First you create the theme (name:CustomTheme) for your Activity in your res/values/styles.xml:

<style name="CustomTheme" parent="@android:style/Theme">
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" 
    parent="@android:style/TextAppearance.Widget.TabWidget">
    <item name="android:textSize">20sp</item>
    <item name="android:textStyle">bold</item>
</style>

Then in your androidManifest.xml you specify the theme above for your TabActivity or Activity containing your TabWidget:

<activity android:name="MyTabActivity" android:theme="@style/CustomTheme">

This will serve you with the output you want (of course you should change the size and style for your preference).

落日海湾 2024-11-10 03:13:22

它不漂亮,但尝试这个肮脏的修复:

TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
View tabView = tw.getChildTabViewAt(0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setTextSize(20);

 //Do this to hack font size of title text
 LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
 TabWidget tw = (TabWidget) ll.getChildAt(0);

 // for changing the text size of first tab
 RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
 TextView lf = (TextView) rllf.getChildAt(1);
 lf.setTextSize(21);
 lf.setPadding(0, 0, 0, 6);

Its not pretty but try this Dirty Fix :

TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
View tabView = tw.getChildTabViewAt(0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setTextSize(20);

or

 //Do this to hack font size of title text
 LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
 TabWidget tw = (TabWidget) ll.getChildAt(0);

 // for changing the text size of first tab
 RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
 TextView lf = (TextView) rllf.getChildAt(1);
 lf.setTextSize(21);
 lf.setPadding(0, 0, 0, 6);
一张白纸 2024-11-10 03:13:22

稍微概括一下:

final TabWidget tw = (TabWidget)mTabHost.findViewById(android.R.id.tabs);
    for (int i = 0; i < tw.getChildCount(); ++i)
    {
        final View tabView = tw.getChildTabViewAt(i);
        final TextView tv = (TextView)tabView.findViewById(android.R.id.title);
        tv.setTextSize(20);
    }

Slightly generalized:

final TabWidget tw = (TabWidget)mTabHost.findViewById(android.R.id.tabs);
    for (int i = 0; i < tw.getChildCount(); ++i)
    {
        final View tabView = tw.getChildTabViewAt(i);
        final TextView tv = (TextView)tabView.findViewById(android.R.id.title);
        tv.setTextSize(20);
    }
如梦 2024-11-10 03:13:22

我在我的代码中使用了这段代码,但它仅对第一个选项卡有效,其他 3 个选项卡仍然不变。

    TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
    View tabView = tw.getChildTabViewAt(0);
    TextView tv = (TextView)tabView.findViewById(android.R.id.title);
    tv.setTextSize(10);

i use this piece of code in my Code but it effect only on first Tab the other 3 Tabs are still unchanged.

    TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
    View tabView = tw.getChildTabViewAt(0);
    TextView tv = (TextView)tabView.findViewById(android.R.id.title);
    tv.setTextSize(10);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文