Home » Android » user interface – Android: How can I access the default text color? (No theme, just the standard one)

user interface – Android: How can I access the default text color? (No theme, just the standard one)

Posted by: admin June 15, 2020 Leave a comment

Questions:

very short question: if I want to set some text (in a TextView) back to the default text color, how can I do this?

I’m not using any themes.

How to&Answers:

I used the following way: At the initialization I backuped the default color and when I had to reset I just used the stores value.

Answer:

I used the solution from jellyfish’s comment on the first answer. A lot of code for something so simple as removing color. To make it clear:

private TextView myTextView;
private int defaultTextColor;

public void onCreate(Bundle savedInstanceState) {
    myTextView = (TextView) findViewById(R.id.myTextView);
    defaultTextColor = myTextView.getTextColors().getDefaultColor();
}

public void changeColorBack() {
    myTextView.setTextColor(defaultTextColor);
}

Answer:

You can create a new TextView and get the color from it.

TextView dummy = new TextView(getActivity());
myTextView.setTextColor(dummy.getTextColors());

Answer:

android:textColor=

Should do the trick, can also be invoked dynamic:

setTextColor(int)

http://developer.android.com/reference/android/widget/TextView.html for more on TextView