Skip to content

Instantly share code, notes, and snippets.

@bleszerd
Created September 6, 2021 12:26
Show Gist options
  • Save bleszerd/04d454abb427ce8f2ea1b341343128b9 to your computer and use it in GitHub Desktop.
Save bleszerd/04d454abb427ce8f2ea1b341343128b9 to your computer and use it in GitHub Desktop.
Swap note custom view
class NoteSwapView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr) {
//Inflating layout
private val binding = NoteSwapViewBinding.inflate(LayoutInflater.from(context), this, true)
init {
prepareView(attrs)
//...
}
//Handle component init state
private fun prepareView(attrs: AttributeSet?) {
attrs?.let { attributeSet ->
val attributes = context.obtainStyledAttributes(attributeSet, R.styleable.NoteSwapView)
//Manage attrs
val title = attributes.getString(R.styleable.NoteSwapView_note_title)
val text = attributes.getString(R.styleable.NoteSwapView_note_text)
val coverImage = attributes.getDrawable(R.styleable.NoteSwapView_note_image_drawable)
attributes.recycle()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment