Is it possible to change the colour of the FadingEdge of a Listview?
Asked Answered
S

3

4

I want to give the effect that the ListView has faded from whatever is around it. By default it is set to whatever colour your ListView is. I can adjust the orientation of the FadingEdge and the size of the FadingEdge but not the colour. Is it possible?

Spanishamerican answered 29/10, 2010 at 10:14 Comment(0)
F
5

Yes you can !

setCacheColorHint(Color.WHITE);
Fredfreda answered 29/10, 2010 at 11:59 Comment(3)
Thanks, that does do what I want, but it also sets the background colour while scrolling. Is there a way to separate the two?Spanishamerican
Give a background color to your cells.Fredfreda
And give your listView the same background as the cells. Obviously won't work with images as background (see solution below)Absorbance
I
14

You'll need to create a new class that extends ListView.

package com.mypackage;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class ColorFadeListView extends ListView
{
  // fade to green by default
  private static int mFadeColor = 0xFF00FF00;
  public ColorFadeListView(Context context, AttributeSet attrs)
  {
    this(context, attrs,0);
  }
  public ColorFadeListView(Context context, AttributeSet attrs, int defStyle)
  {
    super(context,attrs,defStyle);      
    setFadingEdgeLength(30);
    setVerticalFadingEdgeEnabled(true);
  }
  @Override
  public int getSolidColor()
  {
    return mFadeColor;
  }
  public void setFadeColor( int fadeColor )
  {
    mFadeColor = fadeColor;
  }
  public int getFadeColor()
  {
    return mFadeColor;
  }
}

You can use this list view identically to a normal ListView (though you'll have to cast it properly to use the fadeColor accessor methods). In your XML, instead of defining an object as <ListView android:properties.../> define it as <com.mypackage.ColorFadeListView android:properties.../>

Iridissa answered 4/5, 2011 at 2:32 Comment(2)
Is there any way to accomplish with the fading edge on the actionbar for honeycomb?Caracole
This doesn't work for me on a Motorola Razer (Android 2.3.5). I get the size 30 fade areas, but they are black. Works on a 2.3 emulator though and on a HTC Desire S with Android 2.3.5.Krug
F
5

Yes you can !

setCacheColorHint(Color.WHITE);
Fredfreda answered 29/10, 2010 at 11:59 Comment(3)
Thanks, that does do what I want, but it also sets the background colour while scrolling. Is there a way to separate the two?Spanishamerican
Give a background color to your cells.Fredfreda
And give your listView the same background as the cells. Obviously won't work with images as background (see solution below)Absorbance
K
0

You can try this (it's a hack, I know):

int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);

I took advantage of the fact that the glow effect is actually a shared Drawable and applied a filter on it: http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/

Kinser answered 9/12, 2013 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.