Reputation: 784
In my layout file, I don't explicitly define the text color of my ButtonView, so at runtime it renders as the default color (which is black).
In response to user input, I will set the text color of my button to Red, using the setTextColor()
method. Then in response to another user input, I will need to revert to the default color. What's the best way to achieve it? I am looking for a clearTextColor()
method but didn't find one.
Upvotes: 0
Views: 421
Reputation: 17085
There is no guaranty the default color can be black , as each OEM can customize android platform.
You can use ValueAnimator to set the text color and reset it to default color when required
Here is a sample code.
Change the color
final Button button = (Button)findViewById(R.id.button);
final ValueAnimator colorAnimation2 = ValueAnimator.ofObject(new ArgbEvaluator(), button.getCurrentTextColor(), Color.RED);
colorAnimation2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
button.setTextColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation2.start();
Reset to default color
colorAnimation2.reverse();
Upvotes: 1
Reputation: 4185
You can reset it by setting the color to black something like this: text.setTextColor(Color.BLACK), or text.setTextColor(Color.rgb(0,0,0))
Upvotes: 0