开发者

How to update ImageButton BackgroundColor in RemoteViews

开发者 https://www.devze.com 2022-12-22 04:19 出处:网络
I have an appwidget which has got a ImageButton.I can update ImageButton ima开发者_开发技巧ge but i can\'t update backgroundcolor with using setInt() method;because imagebutton setBackgroundColor is n

I have an appwidget which has got a ImageButton.I can update ImageButton ima开发者_开发技巧ge but i can't update backgroundcolor with using setInt() method;because imagebutton setBackgroundColor is not annoated with RemotableViewMethod.class.What can i do else?


http://developer.android.com/reference/android/widget/RemoteViews.html#setInt%28int,%20java.lang.String,%20int%29

Example:

rv.setInt(R.id.view_id, "setBackgroundColor", 0xFF0000FF);


You can try using a different layout in your RemoteViews constructor that has the right background color. You create a RemoteViews object on every update, and you tell that RemoteViews object what layout to use. From my testing, if you inflate something different than before, that will replace what the app widget presently uses. The various RemoteViews setters are for things that you cannot readily handle via layouts (e.g., dynamic text for a TextView).


You can use ImageView instead of layout background, we can set ImageView src to change background (may be you will use android:scaleType="fitXY")

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号