Set drawable dynamically for AnalogClock widget

a 夏天 提交于 2019-12-10 11:44:35

问题


How to do that?

I have AnalogClock on my xml. And I want drawable for the android:dial to change programatically.

I tried

remoteviews.setImageViewResource(R.id.AnalogClock, R.drawable.w0);

or

remoteviews.setInt(R.id.AnalogClock, "setDialResource", R.drawable.w0);

Both can not accomplish it. Anyone manage to do this?


回答1:


Finally make it works. I put transparent image on AnalogClock android:dial Then use FrameLayout to overlay ImageView and AnalogClock.

Then use

remoteviews.setInt(R.id.ImageView, "setBackgroundResource", R.drawable.w0);

to change the ImageView image. It is feasible solution at the moment.




回答2:


Normally remoteviews.setImageViewResource(R.id.AnalogClock, R.drawable.w0) should do the trick. Are you sure that the View refferenced by R.id.AnalogClock is of type ImageView



来源:https://stackoverflow.com/questions/9398362/set-drawable-dynamically-for-analogclock-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!