Android Studio marks as error this line:
public class ParallaxView extends ImageView
Here the error:
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.
It recommends me to extend AppCompatImageView
but then my JUnit test don't pass because AppCompatImageView
needs a mock Context
with resources and Imageview
doesn't need this.
Here the question to solve the other problem:
NullPointerException creating an AppCompatImageView with mock Context
Can I ignore this error and use ImageView? Any other solution?
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.
androidx.appcompat.widget.AppCompatImageView. A ImageView which supports compatible features on older versions of the platform, including: Allows dynamic tint of its background via the background tint methods in androidx.
Using AppCompat
widgets allows you to have some material design (and other new) features on devices with pre-Lollipop versions of Android.
At this point AppCompatImageView
only provides the support for background tint and vector drawables. If you don't use them, then extending the regular ImageView
will be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With