No style ViewPagerIndicator in combination with SherlockActionBar

帅比萌擦擦* 提交于 2019-11-29 23:01:57

In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.

Example:

<style name="myTheme" parent="@style/Theme.Sherlock">

    <!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
    <item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
    <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
    <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>

    <!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
    <item name="vpiCirclePageIndicatorStyle">@style/myCirclePageIndicator</item>


    <!-- Put whatever other styles you want to define in your custom theme -->
</style>

<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
    <item name="fillColor">@color/my_custom_circle_indicator_fill_color</item>
</style>

Then in your Manifest, set android:theme="@style/myTheme" to the <application> or to your <activity>s.

Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.

I accidentally removed android:layout_weight="1" when adding styles.

So for other who want to implement VPI with ABS:

layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.viewpagerindicator.TabPageIndicator
        android:id="@+id/indicator"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        style="@style/StyledIndicators" />
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
</LinearLayout>

styles.xml:

 <style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
            etc.
        </style>   

        <style name="StyledIndicators" parent="Theme.BataApp">
            <item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
            <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
            <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
        </style>

Thank you @Reinier! :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!