Created
September 6, 2021 12:26
-
-
Save bleszerd/04d454abb427ce8f2ea1b341343128b9 to your computer and use it in GitHub Desktop.
Swap note custom view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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