RemoteViews使用setImageResource出错

本文解析了使用android.support.v7.widget.AppCompatImageView时遇到的RemoteViews$ActionException错误,并提供了有效的解决方案。问题出现在23.1.0版本的AppCompat支持库中,因缺少@RemotableViewMethod注解导致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误提示:

android.widget.RemoteViews$ActionException:
view: android.support.v7.widget.AppCompatImageView can’t use method with RemoteViews: setImageResource(int)

解决方法:

setting the appcompat version to ‘com.android.support:appcompat-v7:23.0.1’ or lower makes the error go away.

原因:

Issue:
android.support.v7.widget.AppCompatImageView introduced in version 23.1.0 of appcompat-v7 support library is missing the annotation:
@android.view.RemotableViewMethod for the following
methods:setImageResource(int)、setBackgroundResource(int)
Hence breaking RemoveViews#apply(Context, ViewGroup) when the remote view contains an ImageView and either of the above mentioned methods are called.

Details:
ImageView#setImageResource(int) and View#setBackgroundResource(int) are both annotated with @RemotableViewMethod annotation so it works with the RemoveViews API.

However since the @RemotableViewMethod annotation is not itself annotated as @Inherited, subclasses of ImageView and View classes when they override the 2 methods mentioned earlier (what AppCompatImageView did), the check for the RemotableViewMethod annotation in RemoveViews#getMethod(View, String, Class) fails for annotation not present.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值