Java 如何将可绘制视图指定给ImageView

Java 如何将可绘制视图指定给ImageView,java,android,android-resources,cyanogenmod,Java,Android,Android Resources,Cyanogenmod,我正在致力于将光环添加到cyanogenmod 11中。为此,我使用了一种方法,可以得到光晕的活动状态或不活动状态,然后相应地给它分配图像 首先,这是我最近一次尝试的代码(我已经多次尝试完成此任务)-> 现在这里,它说找不到symbol:method getPackageName() 早些时候,我也曾多次尝试使用setImageResource(R.drawable.ic_notify_halo_pressed) 但这给了我NPE 然后我还尝试使用: Resources resources =

我正在致力于将光环添加到cyanogenmod 11中。为此,我使用了一种方法,可以得到光晕的活动状态或不活动状态,然后相应地给它分配图像

首先,这是我最近一次尝试的代码(我已经多次尝试完成此任务)->

现在这里,它说
找不到symbol:method getPackageName()

早些时候,我也曾多次尝试使用
setImageResource(R.drawable.ic_notify_halo_pressed)
但这给了我NPE

然后我还尝试使用:

Resources resources = getResources();        mHaloButton.setImageDrawable(resources.getDrawable(R.drawable.ic_notify_halo_pressed));
但这给了错误
找不到符号:方法getResources()

我还尝试了
mhalobuton.setImageDrawable(R.drawable.ic\u notify\u halo\u按下)
但它给出了错误:
android.widget.ImageView中的setImageDrawable(android.graphics.drawable.drawable)不能应用于(int)

所以我知道它需要资源ID,但是我怎么才能得到它呢


请注意:我不是在构建应用程序,这也不是android studio项目。我正在尝试将halo移植到cyanogenmod 11。

替换
Resources=getResources()
Resources Resources=mContext.getResources()因为您已经引用了上下文


同样适用于
getPackageName()
。将其替换为
mContext.getPackageName()

转换为位图,然后应用。谢谢,它成功了:DYou're welcome@nonamehman!:-)
Resources resources = getResources();        mHaloButton.setImageDrawable(resources.getDrawable(R.drawable.ic_notify_halo_pressed));