因为我正在为 API 级别 7 及更高级别进行开发,所以我setAlpha(float)
无法使用。因此,我已经实现了一个遍历给定的所有子元素的方法,ViewGroup
并尝试找到一种方法来设置 alpha 以使元素几乎是透明的。不幸的是,我无法想出一种方法来使其ListView
及其项目透明。我该如何进行?
我的方法:
public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = viewGroup.getChildAt(i);
view.setEnabled(enabled);
if (!enabled) {
if (view instanceof TextView) {
int curColor = ((TextView) view).getCurrentTextColor();
int myColor = Color.argb(ALPHA_NUM, Color.red(curColor),
Color.green(curColor),
Color.blue(curColor));
((TextView) view).setTextColor(myColor);
} else if (view instanceof ImageView) {
((ImageView) view).setAlpha(ALPHA_NUM);
} else if (view instanceof ListView) {
// How do I set the text color of the subitems in this listview?
} else {
try {
Paint currentBackgroundPaint =
((PaintDrawable) view.getBackground()).getPaint();
int curColor = currentBackgroundPaint.getColor();
int myColor = Color.argb(ALPHA_NUM, Color.red(curColor),
Color.green(curColor), Color.blue(curColor));
view.setBackgroundColor(myColor);
} catch (NullPointerException e) {
Log.d("viewNotFound", "View " + view.getId() + " not found..");
e.getStackTrace();
}
}
if (view instanceof ViewGroup) {
enableDisableViewGroup((ViewGroup) view, enabled);
}
}
}
}