【问题标题】:i want to change the color of swipe tab in viewpager我想更改 viewpager 中滑动选项卡的颜色
【发布时间】:2015-01-13 09:51:12
【问题描述】:

我想使用 viewpager 更改滑动标签的背景颜色。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    >
    </android.support.v4.view.ViewPager>
</RelativeLayout>

【问题讨论】:

标签: android


【解决方案1】:

我想你想自定义你的 viewpager 标签栏。 这是用于设置 viewpager 选项卡的非常有用的库:PagerSlidingTabTrip

比android默认的viewpager标签栏好。

示例 xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app1="http://schemas.android.com/apk/res/mobi.thevip"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
        android:id="@+id/action_bar_line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#C0C0C0" />

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/indicator"
        android:layout_width="match_parent"
        android:layout_below="@+id/action_bar_line"
        android:layout_height="@dimen/abs__action_bar_default_height"
        app1:pstsIndicatorColor="@color/tab_indicator"
        app1:pstsUnderlineColor="@color/tab_underline_indicator" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/indicator" >
    </android.support.v4.view.ViewPager>
</RelativeLayout>

您可以阅读库自述文件来使用它。

希望对您有所帮助!

【讨论】:

  • 滑动标签的背景颜色是否取决于应用主题...如果我更改主题颜色,是否可以更改标签背景颜色。
  • @Ajaz:滑动标签的背景,我认为可以这样更改:stackoverflow.com/questions/21335267/… 谢谢你,Johnson - 这个链接! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-21
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
相关资源
最近更新 更多