![](https://images0.cnblogs.com/blog/413024/201310/23094921-b4644441fc79468f89dfd7ded8ecc283.png)
如果是用Linearlayout里面动态添加Linearlayout的情况,就要代码控制了
// 就是为了改变颜色。
ly.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
foodName.setTextColor(getResources().getColor(R.color.color_text_p));
}
if (event.getAction() == MotionEvent.ACTION_UP) {
foodName.setTextColor(getResources().getColor(R.color.color_text));
}
// 乱移就要用这个
if (event.getAction() == MotionEvent.ACTION_CANCEL) {
foodName.setTextColor(getResources().getColor(R.color.color_text));
}
return false;
}
});
别忘了给相应的ly加上setOnClickListener