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

时间:2010-10-29 10:14:53

标签: android listview colors edge fading

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

3 个答案:

答案 0 :(得分: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;
  }
}

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

答案 1 :(得分:5)

是的,你可以!

setCacheColorHint(Color.WHITE);

答案 2 :(得分:0)

你可以试试这个(这是一个黑客,我知道):

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

我利用了一个事实,即发光效果实际上是一个共享的Drawable并在其上应用了一个过滤器:http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/

相关问题