【发布时间】:2017-03-23 10:59:10
【问题描述】:
Android Studio 将此行标记为错误:
public class ParallaxView extends ImageView
这里是错误:
This custom view should extend android.support.v7.widget.AppCompatImageView instead less... (Ctrl+F1)
In order to support features such as tinting, the appcompat library will automatically load special appcompat replacements for the builtin widgets.
However, this does not work for your own custom views. Instead of extending the android.widget classes directly, you should instead extend one of the delegate classes in android.support.v7.widget.AppCompat.
它建议我扩展 AppCompatImageView 但我的 JUnit 测试没有通过,因为 AppCompatImageView 需要一个带有资源的模拟 Context 而 Imageview 不需要这个。
这里的问题解决其他问题:
NullPointerException creating an AppCompatImageView with mock Context
我可以忽略这个错误并使用 ImageView 吗?还有其他解决方案吗?
【问题讨论】:
标签: android android-view android-support-library android-custom-view android-context