本文介绍了机器人 - getResources()和静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类
公共类preferences扩展preferenceActivity实现OnShared preferenceChangeListener
出这个我尝试从另一个调用类中的方法。该方法包括:
mFoo.setTextColor(getResources()。的getColor(R.color.orange))
但它不工作。它告诉我 getResources
不是静态的...我怎样才能改变这种?
解决方案
This means you are trying to call getResources()
from a static method, rather than a regular (instance) method. The easiest thing to do in your case, if mFoo
is a TextView
or some other widget, is to call getResources()
on the Context
available from the widget:
mFoo.setTextColor(mFoo.getContext().getResources().getColor(R.color.orange));
However, the fact that you are trying to reference a widget named mFoo
from a static method scares the crap out of me. This is just asking for a memory leak. I think you really need to reconsider your use of static data members and methods.
这篇关于机器人 - getResources()和静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!