是否可以更改Listview的FadingEdge的颜色?

Not*_*Man 4 android listview colors fading

我想说明ListView已经从周围的任何东西中消失了.默认情况下,它设置为ListView的任何颜色.我可以调整FadingEdge的方向和FadingEdge的大小,但不能调整颜色.可能吗?

Tho*_*mer 14

您需要创建一个扩展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;
  }
}
Run Code Online (Sandbox Code Playgroud)

您可以将此列表视图与法线相同地使用ListView(尽管您必须正确地使用fadeColor访问器方法).在XML中,而不是定义对象作为<ListView android:properties.../>定义<com.mypackage.ColorFadeListView android:properties.../>


Wil*_*cle 5

是的你可以 !

setCacheColorHint(Color.WHITE);
Run Code Online (Sandbox Code Playgroud)

  • 为细胞提供背景颜色. (2认同)