Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 290
NotACleverMan Avatar asked Dec 02 '22 04:12

NotACleverMan


1 Answers

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.../>

like image 183
Thomson Comer Avatar answered Dec 05 '22 08:12

Thomson Comer