【问题标题】:Styling Tab Widget's using XML使用 XML 设置 Tab Widget 的样式
【发布时间】:2014-03-06 17:07:48
【问题描述】:

所以我很难使用 xml 设置标签小部件的样式。我搜索过的所有地方似乎要么建议以编程方式执行此操作的解决方案,要么参考 actionBarTab 样式 >:|

我想要实现的是使用 http://android-holo-colors.com/ 生成的 tabwidget drawables 中的自定义选项卡

我设法得到了

所以在我的自定义主题中我有这个代码:

<style name="RR.App.Theme" parent="android:Theme.Holo.Light">
...
<item name="android:tabWidgetStyle">@style/RR.Tab.Widget</item>
...
</style>

这是 RR.Tab.Widget 样式:(这些似乎都没有什么区别)

<style name="RR.Tab.Widget" parent="android:Widget.Holo.Light.TabWidget">
<item name="android:background">@drawable/rrtheme_tab_indicator_holo</item>
<item name="android:tabStripEnabled">false</item>
<item name="android:tabStripLeft">@null</item>
<item name="android:tabStripRight">@null</item>
</style>

这是生成的drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/rrtheme_tab_unselected_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/rrtheme_tab_selected_holo" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/rrtheme_tab_unselected_focused_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/rrtheme_tab_selected_focused_holo" />

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/rrtheme_tab_unselected_pressed_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/rrtheme_tab_selected_pressed_holo" />

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/rrtheme_tab_unselected_pressed_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/rrtheme_tab_selected_pressed_holo" />
</selector>

这是它目前的样子:

我要做的就是把这个蓝色变成绿色!

非常感谢您提前提供的帮助:)

【问题讨论】:

    标签: android android-theme android-tabs android-styles tabwidget


    【解决方案1】:

    我建议你看看这个: Customize Tab indicator(死链接)

    还可以使用Android Action Bar Style Generator 自定义标签。我总是用它来让我的标签变成我想要的颜色。

    希望能帮到你

    【讨论】:

    • 太棒了,感谢您的帮助。由于我使用的是已弃用的 TabActivity,因此需要先更新以使用片段和页面查看器。接下来我可能会点击这个,所以我会在完成后发布我的方法。
    猜你喜欢
    • 2014-12-20
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2015-03-03
    • 1970-01-01
    • 2013-02-04
    相关资源
    最近更新 更多