【问题标题】:Custom view ChipTabView is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int). Kotlin自定义视图 ChipTabView 缺少工具使用的构造函数:(Context) 或 (Context,AttributeSet) 或 (Context,AttributeSet,int)。科特林
【发布时间】:2021-08-27 15:47:56
【问题描述】:

嘿,我试图在自定义视图类中传递参数。它给出警告 Custom view ChipTabView is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int)。我不想使用 suppressLint 如何删除此警告有人可以帮助我。我试过这个Custom view is missing constructor used by tools for adapter 我不想更改android studio的设置。我需要适当的解决方案如何以干净的方式实现这一目标。提前致谢

class ChipTabView @JvmOverloads constructor(
    context: Context,
    private val number: Int,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    删除private val number: Int 以使构造函数参数符合布局充气器要求。

    您可以使用 setter 函数将值传递给您的自定义视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多