Android:如何访问默认文本颜色?(没有主题,只有标准的主题)

jel*_*ish 8 user-interface android textcolor

非常简短的问题:如果我想将一些文本(在TextView中)设置回默认文本颜色,我该怎么做?

我没有使用任何主题.

maG*_*aGo 15

我使用了水母对第一个答案的评论解决方案.很多代码用于删除颜色这么简单的事情.说清楚:

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);
}
Run Code Online (Sandbox Code Playgroud)


sch*_*gel 9

我使用以下方式:在初始化时我备份默认颜色,当我不得不重置时,我只使用了存储值.

  • 啊,算了吧,找到了TextView.getTextColors().getDefaultColor().:) 非常感谢你! (15认同)