我正在尝试使用res / values / colors.xml文件中创建的颜色.但是当我动态调用程序时,程序不会编译,而是建议:应该传递已解析的颜色而不是资源ID.
色标:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="gold">#857500</color> <color name="green">#0B3B0B</color> </resources>
活动代码:
title.setTextColor(R.color.green); help.setTextColor(R.color.gold); settings.setTextColor(R.color.gold); logout.setTextColor(R.color.gold); profile.setTextColor(R.color.green);
解决方法
将代码更改为以下内容:
title.setTextColor(getResources().getColor(R.color.green)); help.setTextColor(getResources().getColor(R.color.gold)); settings.setTextColor(getResources().getColor(R.color.gold)); logout.setTextColor(getResources().getColor(R.color.gold)); profile.setTextColor(getResources().getColor(R.color.green));