Jakob Harteg
Jakob Harteg

Reputation: 9747

Change ViewPager's overscroll color

How can I change the overscroll glow effect color of a ViewPager in android? Or is there a way to change the overscroll color for the whole app via themes?

I know of setOverScrollHeader and footer, but these does "logically" of course not work for a viewpager in horizontal mode.

Upvotes: 6

Views: 2248

Answers (3)

Jack'
Jack'

Reputation: 2508

The simplest way to do it is to override colorPrimary for your viewpager using themes.

For example :

In your fragment/activity :

<androidx.viewpager.widget.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/AppTheme.Viewpager" />

In your file styles.xml :

<style name="AppTheme.Viewpager" parent="AppTheme">
    <item name="colorPrimary">#FFFFFF</item>
</style>

Upvotes: 1

Jakob Harteg
Jakob Harteg

Reputation: 9747

Finally found a solution!!

A great library by AndroidAlliance called EdgeEffectOverride.

It easily allows changing the overscroll color of ScrollView, ListView, ExpandableListView, GridView & ViewPager

Link: https://github.com/AndroidAlliance/EdgeEffectOverride

Upvotes: 0

karvoynistas
karvoynistas

Reputation: 1285

Solution 1 : You could call inside the scroll listener the methods setBackground, setBackgroundColor and setAlpha methods to create your own appearance.

Solution 2 : You could create your own AlphaAnimation that it will be triggered inside the scroll listener.

    AlphaAnimation fadeIn = new AlphaAnimation( 0.0f , 1.0f ) ; 
    fadeIn.setDuration(1000);

    yourViewPager.startAnimation(fadeIn);

Upvotes: 0

Related Questions