Android Tabhost 问题 - .setIndicator
首先让我澄清一下,我已经提到了与“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题的根源在于框架代码中的某个地方。果然,我发现了一些线索:
首先,如果你看看
TabWidget
代码,你会看到你在<中设置的标签code>setIndicator 被传递给一个名为LabelIndicatorStrategy
的内部类,该内部类将负责膨胀与选项卡顶部关联的视图。此膨胀是使用 xml 文件 tab_indicator.xml。此布局基于包含ImageView
和TextView
的RelativeLayout
。如果你查看textview的属性,你会发现它引用了android中的一个样式 styles.xml。最后,你意识到我们有这个:所以,现在,有 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 insetIndicator
is passed to an inner class calledLabelIndicatorStrategy
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 aRelativeLayout
containing anImageView
and aTextView
. 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 :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.
我已经通过减小字体大小解决了上述问题,请检查
Style.xml
的以下代码:i have solved the above issue by decreasing the size of Font, check the below code of
Style.xml
: