ListItem选中时只改变文字的颜色

时间:2025-01-25 09:37:32
ListItem选中时只改变文字的颜色ListItem选中时只改变文字的颜色 继承父状态,然后使用Selector
如果是用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