1

I am adding a ViewPager to my app, together with an picture indicator.

I want the shape of the indicator to be a thin line instead of the usual dots.

For that, I have taken a reference from this answer here.

I have tried to modify the XML files given, like this:

default_dot.xml ---> default_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="line">

            <solid android:color="@android:color/darker_gray"/>

            <corners
                android:bottomRightRadius="7dp"
                android:bottomLeftRadius="7dp"
                android:topLeftRadius="7dp"
                android:topRightRadius="7dp" />
        </shape>
    </item>
</layer-list>

selected_dot.xml -----> selected_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="line">


            <solid android:color="@color/colorAccent"/>

            <corners
                android:bottomRightRadius="7dp"
                android:bottomLeftRadius="7dp"
                android:topLeftRadius="7dp"
                android:topRightRadius="7dp" />
        </shape>
    </item>
</layer-list>

And the file tab_selector.xml remains the same, just change the name of the corresponding xml files.

So, well, the result of all this, is that, the selected_line.xml (the pink one) is showed, however, the default_line.xml is not showed, so I can just see the pink like moving to the right/left as I swipe the pictures, but no default grey lines.

codeKiller
  • 5,493
  • 17
  • 60
  • 115

1 Answers1

0

Please make changes to your selected_line.xml as follows

<item>

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">

        <stroke
            android:width="@dimen/activity_horizontal_margin"
            android:color="@color/colorAccent" />
        <size android:height="1dp" />

        <solid android:color="@color/colorAccent" />

        <corners
            android:bottomLeftRadius="7dp"
            android:bottomRightRadius="7dp"
            android:topLeftRadius="7dp"
            android:topRightRadius="7dp" />

    </shape>

</item>

NileshW
  • 11
  • 3