Android Tabhost 问题 - .setIndicator

发布于 2024-09-13 10:31:18 字数 275 浏览 2 评论 0原文

首先让我澄清一下,我已经提到了与“Android - TAbhost”相关的问题。

我已经用谷歌搜索了“Android Tabhost”,但未能找到解决方案。

我的问题是:

如果有 <3 个选项卡,那就没问题。 但 如果我们有 4 个选项卡,其指示器标题为 TabHost1、TabHost2、TabHost3、TabHost4),则支持。但是 Tab 中的这个标题并没有与 tab 配合。那么有什么方法可以将标题文本(即指示器)放入选项卡中吗?

First let me clarify that i have already referred the SO question related to "Android - TAbhost".

I have done googling about "Android Tabhost" but failed to find the solution.

My problem is:

If are having <3 tabs then it is fine.
but
Supporse if we are having 4 tabs with indicator title as TabHost1, TabHost2, TabHost3, TabHost4). But this title in Tab does not get fitted with tab. so is there any way to fit the Title Text (i.e. indicator) inside the tab ??

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

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

发布评论

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

评论(2

强者自强 2024-09-20 10:31:18

我认为问题的根源在于框架代码中的某个地方。果然,我发现了一些线索:

首先,如果你看看 TabWidget 代码,你会看到你在<中设置的标签code>setIndicator 被传递给一个名为 LabelIndicatorStrategy 的内部类,该内部类将负责膨胀与选项卡顶部关联的视图。此膨胀是使用 xml 文件 tab_indicator.xml。此布局基于包含 ImageViewTextViewRelativeLayout。如果你查看textview的属性,你会发现它引用了android中的一个样式 styles.xml。最后,你意识到我们有这个:

<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>

所以,现在,有 2 个选择:
首先,通过创建您自己的样式来覆盖样式,在我看来,这将是真正轻松的方法,然后将这些属性更改为更适合您的属性。虽然结果可能不太好。这需要一些测试。
或者,戴上手套并从 TabWidget 类中复制代码,因为这里的另一个问题是我提到的内部类是... PRIVATE 所以,如果我没有记错的话,不可能继承...所以我认为,很多比 styles.xml 的方式痛苦得多。
希望这会对您有所启发,请随时向我通报您收到的信息。我还是有兴趣。

I thought the source of our issue was somewhere in the framework's code. And sure enough, I found some clues :

First, if you look inside the TabWidget code, you will see that the label you set in setIndicator is passed to an inner class called LabelIndicatorStrategy which will take care of inflating the view associated to the top part of the tab. This inflation is done using an xml file tab_indicator.xml. This layout is based on a RelativeLayout containing an ImageView and a TextView. And if you look at the properties of the textview, you will see that it refers to a style in android styles.xml. And here finally, you realize that we have THAT :

<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>

So, now, 2 options :
First, override the style by creating your own style, which in my opinion would be the really painless way and then change these properties to something that suits you better. Though the result might not be very nice. this will require some testing.
Or, put on your gloves and copy the code from the TabWidget class, because another issue here is that the inner class I mentionned is... PRIVATE so, no inheritance possible if I'm not mistaken... SO I think, much much more pain than the styles.xml's way.
Hope this will inspire you, keep me posted of what you get please. I'm still interested.

安人多梦 2024-09-20 10:31:18

我已经通过减小字体大小解决了上述问题,请检查 Style.xml 的以下代码:

<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">
        <item name="android:textSize">12px</item>
        <item name="android:textColor">#1E90FF</item>
    </style>
</resources>

i have solved the above issue by decreasing the size of Font, check the below code of Style.xml:

<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">
        <item name="android:textSize">12px</item>
        <item name="android:textColor">#1E90FF</item>
    </style>
</resources>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文