【问题标题】:Android TabLayout selected tab backgroundAndroid TabLayout 选中标签背景
【发布时间】:2016-07-05 11:43:36
【问题描述】:

真的没有简单的方法来使用 TabLayout 并能够设置选项卡的颜色(选中,未选中)吗?就像选定的标签背景使用colorPrimary,非选定的标签使用colorPrimaryDark 还是什么?我搜索了包括thisthis 等在内的网络。我可以使用解决方案 1 更改背景颜色,但现在指示器不见了,我想要它回来。

这不是很难做到的......

第一个链接的解决方案:

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
        <item name="tabBackground">@drawable/tab_background</item>
</style>

// tab_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/tab_background_selected" android:state_selected="true" />
    <item android:drawable="@drawable/tab_background_unselected" android:state_selected="false" android:state_focused="false" android:state_pressed="false" />
</selector>

回答:

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
        <item name="tabBackground">@drawable/tab_background</item>
        <item name="tabIndicatorColor">@color/colorAccent</item>
        <item name="tabIndicatorHeight">3dp</item>
</style>

【问题讨论】:

    标签: android android-viewpager android-tabs android-tablayout


    【解决方案1】:

    风格变化

      <style name="Base.Widget.Design.TabLayout" parent="android:Widget">
          <item name="tabBackground">@drawable/tab_background</item>
          <item name="tabIndicatorColor">#000000</item> 
          <item name="tabIndicatorHeight">5dp</item>      
      </style> 
    

    【讨论】:

    • 这个答案怎么不隐藏指标?
    • app:tabIndicatorColor="@android:color/transparent" app:tabIndicatorHeight="0dp"
    • 我想你误会了,我希望指示器可用并且显示不隐藏!
    • 我的上帝终于感谢了,简单,容易..我现在连问都觉得很愚蠢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多