否则,<代码>ListView有一个<编码>Selector,该编码将在你发布一个清单项目时使用<代码>可转让<<>代码>。 然而,如果您的列名观点具有坚实的背景,那么你就不能够看到选择者(或任何其他国家)的长效感,因为它属于清单项目的范围。
If you want to see the selector s longpress animation/selected/pressed state, then the list item s has to have a transparent background when the item is selected/pressed/longpressed. You can do it by using a StateListDrawable as your item s background instead of a solid color.
http://developer.android.com/fer/android/graphics/drawable/StateListDrawable.html。
public class ColorfulListItemDrawable extends StateListDrawable {
private final PaintDrawable mColor;
public ColorfulListItemDrawable(int color) {
mColor = new PaintDrawable(color);
initialize();
}
private void initialize() {
Drawable color = mColor;
Drawable selected = new ColorDrawable(Color.TRANSPARENT);
addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled,
android.R.attr.state_window_focused}, selected);
addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled,
android.R.attr.state_window_focused,android.R.attr.state_selected}, selected);
addState(new int[] {android.R.attr.state_enabled,android.R.attr.state_window_focused, android.R.attr.state_selected}, selected);
addState(new int[] {}, color);
}
public void setColor(int color) {
mColor.getPaint().setColor(color);
mColor.invalidateSelf();
}
}