private TextView[] tvConstellations = new TextView[12];
//获取当前id元素并在其点击的时候修改其颜色
for (int i = 0; i < 12; i++) {
int resId = getResources().getIdentifier("tv_constellation_" + (i+1), "id", getPackageName());
tvConstellations[i] = findViewById(resId);
final int j = i;
tvConstellations[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int color = tvConstellations[j].getCurrentTextColor(); // 获取 TextView 的实际颜色值
int targetColor = ContextCompat.getColor(getApplicationContext(), R.color.color_ff7804); // 获取目标颜色的实际值
if (color == targetColor) {
tvConstellations[j].setTextColor(getResources().getColor(R.color.color_66625e));
tvConstellations[j].setBackgroundResource(R.drawable.service_item_background);
constellationArr.removeAll(Collections.singleton((j+1)+""));
}else{
tvConstellations[j].setTextColor(getResources().getColor(R.color.color_ff7804));
tvConstellations[j].setBackgroundResource(R.drawable.service_item_selected);
constellationArr.add((j+1)+"");
}
}
});
}
//获取当前按钮颜色,点击的时候修改其颜色
case R.id.tv_sex_male:{ //男
int colorMale = tv_sex_male.getCurrentTextColor(); // 获取 TextView 的实际颜色值
int targetColor = ContextCompat.getColor(getApplicationContext(), R.color.color_ff7804); // 获取目标颜色的实际值
if (colorMale == targetColor) {
tv_sex_male.setTextColor(getResources().getColor(R.color.color_66625e));
tv_sex_male.setBackgroundResource(R.drawable.service_item_background);
reqServicePerson.setSex("");
}else{
tv_sex_male.setTextColor(getResources().getColor(R.color.color_ff7804));
tv_sex_male.setBackgroundResource(R.drawable.service_item_selected);
reqServicePerson.setSex("0");
}
tv_sex_female.setTextColor(getResources().getColor(R.color.color_66625e));
tv_sex_female.setBackgroundResource(R.drawable.service_item_background);
break;
}