list点击项高亮其他默认

时间:2023-03-08 17:23:56

// 点击项颜色高亮,其他默认
if (position != lastPosition && onClickItemView != null) {
TabMenu lastTabMenu = availableTabs.get(lastPosition);
View oldviewTip = onClickItemView.findViewById(R.id.view_tip);
ImageView oldImgMenu = (ImageView) onClickItemView
.findViewById(R.id.img_menu);
TextView oldTvMenu = (TextView) onClickItemView
.findViewById(R.id.tv_menutip);
onClickItemView.setBackgroundDrawable(null);
oldviewTip.setVisibility(View.GONE);
oldImgMenu.setImageResource(ResourceUtil
.getDrawableResourceId(lastTabMenu.getIconName()));
oldTvMenu.setTextColor(getResources().getColor(
R.color.first_text_default_color));
}
TabMenu tabMenu = availableTabs.get(position);
view.setBackgroundColor(getResources().getColor(
R.color.first_bg_pressed_color));
viewTip.setVisibility(View.VISIBLE);
imgMenu.setImageResource(ResourceUtil.getDrawableResourceId(tabMenu
.getHlIconName()));
tvMenu.setTextColor(getResources().getColor(R.color.white));

onClickItemView = view; // 方便下次清空
lastPosition = position; // 方便下次点击其他Item时,将此选中的Item还原