Ok, so i need to change two buttons´ text color after they have been clicked, and I´ve this:
manButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
manButton.setTextColor(getApplication().getResources().getColor(R.color.selectedGender));
womanButton.setTextColor(getApplication().getResources().getColor(R.color.unselectedGender));
}
});
But the method getColor()
looks to be deprecated since Android M, and as my app is just for android lollipop and higher I need to solve this issue. I´ve been searching on the net and I´ve discovered that since Android M for getting a color from an xml you have to use: ContextCompat.getColor(context, R.color.my_color)
and I´ve tried it, but it says it can not resolve the symbol context, I´ve also tried changing context
to this
, as it is inside an Activity, but it gaves me this error:
Wrong 1st argument type. Found: 'android.view.View.OnClickListener', required: 'android.content.Context'
getColor(android.content.Context,int) in ContextCompat cannot be applied to (anonymous android.view.View.OnClickListener,int)
So, what should I do? Thanks a lot!