【问题标题】:customize the height of tab indicator in view pager?在视图寻呼机中自定义标签指示器的高度?
【发布时间】:2013-05-23 22:20:28
【问题描述】:

我正在寻找像 pininterest 这样的标签指示器样式,其中指示器看起来不像正常的“android”样式。是否有一些属性可以设置指示器高度?请查看下图。

【问题讨论】:

    标签: android view android-viewpager viewpagerindicator android-styles


    【解决方案1】:

    这可能不是一个合适的解决方案,而且问题确实很老,但是由于我没有找到任何合适的解决方案,所以我就是这样做的:

    我创建了一个layerList文件,叫做indicator:

    <layer-list
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#FF0000" />
            </shape>
        </item>
        <item android:bottom="3dp">
            <shape android:shape="rectangle">
                <solid android:color="#efefef" />
            </shape>
        </item>
    </layer-list>
    

    只需将其设置为我的标签指示器背景:

    <style name="CustomTabPageIndicator" parent="@android:style/Widget.Holo.ActionBar.TabView">
            <item name="android:background">@drawable/indicator</item>
        </style>
    

    我也将此主题应用于我的 actionBar:

    <style name="MyActionBarTheme" parent="android:style/Widget.Holo.ActionBar">
                 <item name="android:actionBarTabStyle">@style/CustomTabPageIndicator</item>
            </item> </style>
    

    之所以有效,是因为在 indicator.xml 中,第一个形状是较低的形状,这是实际的指示器,并且我通过为另一个颜色与操作栏颜色相同的形状提供底部填充来设置它的高度。

    【讨论】:

      【解决方案2】:

      只需在布局文件中设置 layout_height 属性:

      com.viewpagerindicator.TitlePageIndicator
      android:layout_height="@dimen/indicator_height"
      

      【讨论】:

        【解决方案3】:

        使用材质设计的TabLayout,可以用app:tabIndicatorHeight设置高度

        <com.google.android.material.tabs.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorHeight="4dp" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-01-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-25
          • 1970-01-01
          相关资源
          最近更新 更多