How to set the color of an Android ScrollView fading edge?

前端 未结 7 755
攒了一身酷
攒了一身酷 2020-12-04 18:16

I have an Android scrollview with a white background. The fading edge is a white translucent gradient. I would like to change it be black instead of white. I have a ListView

相关标签:
7条回答
  • 2020-12-04 18:20

    Just found it out by trial and error.

    Simply set android:background="@color/yourColor" for the <ScrollView>. It will set the shadow to the given colour.

    0 讨论(0)
  • 2020-12-04 18:24

    EDIT: this does not answer the question, which was asking for ScrollView. This answer only works on AbsListView and descendants (including ListView).


    Fading edge color is controlled by the android:cacheColorHint attribute.

    E.g.:

    <ScrollView android:cacheColorHint="#ff000000" android:background="#ffffffff" />

    will set the background to white, and the cacheColorHint is used to draw the fading edge color -- in this case, it would be black.

    0 讨论(0)
  • 2020-12-04 18:31

    If you want a different color fading edge than the background, you have to override the ScrollView's getSolidColor() method. For example:

    @Override
    public int getSolidColor() {
        return Color.rgb(0x30, 0x30, 0x30);
    }
    
    0 讨论(0)
  • 2020-12-04 18:37

    Do this:

      <ScrollView
        android:theme="@style/scrollUpdate"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    

    in values\styles put the style

    <style name="scrollUpdate">
        <item name="colorAccent">@color/yourcolor</item>
        <item name="android:color">@color/yourcolor</item>
        <item name="colorPrimary">@color/yourcolor</item>
        <item name="colorPrimaryDark">@color/yourcolor</item>
    </style>
    

    works to me tks!

    0 讨论(0)
  • 2020-12-04 18:38

    You can use:

        final int glowDrawableId = context.getResources().getIdentifier("overscroll_glow",
                "drawable", "android");
        final Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
        androidGlow.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
    
        int edgeDrawableId = context.getResources().getIdentifier("overscroll_edge", "drawable",
                "android");
        final Drawable androidEdge = context.getResources().getDrawable(edgeDrawableId);
        androidEdge.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
    
    0 讨论(0)
  • 2020-12-04 18:40

    You can use this:

    https://github.com/AndroidAlliance/EdgeEffectOverride

    enter image description here

    Simple clean and working perfect!

    0 讨论(0)
提交回复
热议问题