例如,如果背景为白色,则文本颜色将为黑色。如果BG为黑色,则文本为白色。蓝色BG,黄色文本等。 更新:
// method in MyActivity class
void changeBackgroundColor(int newColor) {
activityLayout.setBackgroundColor(newColor);
int invertingColor = ColorInvertor.invert(newColor);
someTextView.setTextColor(invertingColor);
}
Run Code Online (Sandbox Code Playgroud)
如果我致电activity.changeBackgroundColor(Color.WHITE),则someTextView必须将文本颜色更改为黑色,即ColorInvertor.invert(Color.WHITE) == Color.BLACK,ColorInvertor.invert(Color.BLACK) == Color.WHITE等等。
android ×1