简体   繁体   English

调用需要 API 级别 21(当前最小值为 19):android.view.View()

[英]Call requires API level 21 (current min is 19): android.view.View()

So I want to create a library that use custom view.所以我想创建一个使用自定义视图的库。 I want to inherit View class, but it's error because my minsdk is 19. I need my library to support sdk 19. Is there a way to solve this?我想继承View类,但是报错,因为我的minsdk是19。我需要我的库来支持sdk 19。有没有办法解决这个问题?

class Dummy() :  View(context, attrs, defStyleAttr, defStyleRes) {

You should use another constructor for this.您应该为此使用另一个构造函数。 The one you used is available only from the API 21.您使用的那个只能从 API 21 中获得。

For custom views I use it like this:对于自定义视图,我像这样使用它:

class Dummy @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: View(context, attrs, defStyleAttr)

So 2 things here:所以这里有两件事:

  1. Use View constructor with 3 params.使用带有 3 个参数的 View 构造函数。 Context, attrs, defStyleAttr.上下文、属性、defStyleAttr。
  2. Use @JvmOverloads annotation and default values for parameters to support actually 3 constructors in one line.使用@JvmOverloads 注释和参数的默认值,在一行中实际支持 3 个构造函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用要求API级别21,当前最小值为8 - Call requires API level 21, current min is 8 类需要 API 级别 21(当前最小值为 19):android.hardware.camera2.CameraDevice.StateCallback - Class requires API level 21 (current min is 19): android.hardware.camera2.CameraDevice.StateCallback Android Call需要API级别13(当前最小值为10):android.view.Display #getSize - Android Call requires API level 13 (current min is 10): android.view.Display#getSize L预览:呼叫需要API级别21(当前最小值为20) - L preview: Call requires API level 21 (current min is 20) 调用需要API级别14(当前最小值为8):android.view.ViewGroup#canScrollHorizo​​ntally - Call requires API level 14 (current min is 8): android.view.ViewGroup#canScrollHorizontally Ripple需要API级别21(当前最小值为11),android? - Ripple requires API level 21 (current min is 11), android? 如何在Android Studio中为消息“调用要求API级别21(当前最小值为16)”启用lint错误? - How to enable lint error in Android Studio for message “Call requires API level 21 (current min is 16)”? 通话需要 API 级别 21(当前最低为 14):android.speech.tts.TextToSpeech#speak - Call requires API level 21 (current min is 14): android.speech.tts.TextToSpeech#speak 调用需要 api 级别 24(当前最小值为 21)新的 android.icu.text.DecimalFormat - call requires api level 24 (current min is 21) new android.icu.text.DecimalFormat 调用需要 API 级别 29(当前最小值为 21):`android.widget.NumberPicker#setTextColor` - Call requires API level 29 (current min is 21): `android.widget.NumberPicker#setTextColor`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM