I want to do this: when the CheckBoxPreference is unchecked, the text color of the CheckBoxPreference's title become gray and if checked, the title's text color reverts to original color (depends on the theme).
What I did until now: I created a new class extending from CheckBoxPreference
.
public class CustomCheckBoxPreference extends CheckBoxPreference{
TextView txtTitle;
int originalTextColor;
public CustomCheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onBindView(View view) {
txtTitle = (TextView) view.findViewById(android.R.id.title);
originalTextColor = txtTitle.getCurrentTextColor();
setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (isChecked()) {
txtTitle.setTextColor(originalTextColor); //it doesn't work
}
else {
txtTitle.setTextColor(Color.GRAY); //it doesn't work
}
return true;
}
});
super.onBindView(view);
}
}
When I run the application, the txtTitle.setTextColor(..)
apparently didn't work, the text color didn't change at all. I also have confirmed with the debugger that the onPreferenceClick
method was called.