pengwang
pengwang

Reputation: 19956

Is there a way to disable fading that a viewPager has scroll to edges?

Scrollable views such as the ListView have a fade blue effect along the edges where there is no content and scroll to the end. How can I close the effect?

at listview i can use :

 setHorizontalFadingEdgeEnabled(false);
 android:fadingEdge="none"
 android:requiresFadingEdge="none"

but at the viewPager not useful,can give me some advice

Upvotes: 31

Views: 12179

Answers (4)

silvan
silvan

Reputation: 211

Java:

((RecyclerView)viewPager.getChildAt(0)).setOverScrollMode(View.OVER_SCROLL_NEVER);

Upvotes: 2

HUAN XIE
HUAN XIE

Reputation: 225

 viewPager2.getChildAt(0)?.overScrollMode = RecyclerView.OVER_SCROLL_NEVER

Upvotes: 3

Egos Zhang
Egos Zhang

Reputation: 1364

pengwang's answer is good,but it is above android 10.If we use lower version.Try this.

 try{
    Method method = context.getClass().getMethod("setOverScrollMode",int.class);
    Field field = context.getClass().getField("OVER_SCROLL_NEVER");
    if(method!=null && field!=null){
        method.invoke(viewpager,field.getInt(View.class));
    }
}
catch(Exception e){

}

Upvotes: -2

pengwang
pengwang

Reputation: 19956

I have a solution:

android:overScrollMode="never"

Now everything is OK. I found the solution here.

Upvotes: 88

Related Questions