APIレベル7以上で開発しているため、setAlpha(float)
使用できません。そのため、特定の子要素をすべてトラバースViewGroup
し、要素がほぼ透明になるようにアルファを設定する方法を見つけようとするメソッドを実装しました。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);
}
}
}
}