Android: How can I access the default text color? (No theme, just the standard one)
Asked Answered
C

4

8

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.

Cestoid answered 11/5, 2011 at 9:12 Comment(0)
H
9

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.

Hakim answered 11/5, 2011 at 9:18 Comment(3)
Did you use "TextView.getTextColors().getColorForState(stateSet, defaultColor)" or "TextView.getTextColor(Context context, TypedArray attrs, int def)" ?Cestoid
ah, forget it, found TextView.getTextColors().getDefaultColor(). :) Thank you very much!Cestoid
Hey jellyfish, Can you post code of TextView.getTextColors().getDefaultColor() I cann't understand how to use it. Actually I want to apply default textcolor in all my activity. Thanks.Meadow
D
15

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);
}
Donaldson answered 22/10, 2011 at 2:43 Comment(0)
H
9

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.

Hakim answered 11/5, 2011 at 9:18 Comment(3)
Did you use "TextView.getTextColors().getColorForState(stateSet, defaultColor)" or "TextView.getTextColor(Context context, TypedArray attrs, int def)" ?Cestoid
ah, forget it, found TextView.getTextColors().getDefaultColor(). :) Thank you very much!Cestoid
Hey jellyfish, Can you post code of TextView.getTextColors().getDefaultColor() I cann't understand how to use it. Actually I want to apply default textcolor in all my activity. Thanks.Meadow
H
2

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

TextView dummy = new TextView(getActivity());
myTextView.setTextColor(dummy.getTextColors());
Hearken answered 14/10, 2015 at 12:35 Comment(0)
M
-2
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

Mullins answered 11/5, 2011 at 9:16 Comment(2)
TextView tv = (TextView) findViewById(R.id.TextView); tv.setTextColor(1);Mullins
hmh, sorry, text became black instead of the usual grey. :/Cestoid

© 2022 - 2024 — McMap. All rights reserved.