Skip to content

Instantly share code, notes, and snippets.

@paraya3636
Last active August 16, 2017 08:11
Show Gist options
  • Save paraya3636/4093d9f1b0b53d69584d602b3184b9f6 to your computer and use it in GitHub Desktop.
Save paraya3636/4093d9f1b0b53d69584d602b3184b9f6 to your computer and use it in GitHub Desktop.
KotlinCustomView constructor for Android
class KotlinCustomView
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr)
class KotlinCustomView: View {
// Basic constructors
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
// There constructors style is no problem about…but, no apply padding, gravity…
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super(context, attrs, defStyleAttr)
// For upper API Level 21
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0): super(context, attrs, defStyleAttr, defStyleRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment