Last active
December 15, 2022 13:35
-
-
Save victory316/cea0092c4a666d243c6fa182aee78aa1 to your computer and use it in GitHub Desktop.
CustomView template on Kotlin
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<declare-styleable name="CustomView"> | |
<attr name="customViewAtrribute" format="string" /> | |
</declare-styleable> | |
</resources> |
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 CustomView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : ConstraintLayout(context, attrs, defStyleAttr) { | |
private var binding: CustomViewBinding | |
private var typedArray: TypedArray | |
init { | |
binding = CustomViewBinding.inflate(LayoutInflater.from(context), this, true) | |
typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomView) | |
} | |
} |
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
<com.my.app.CustomView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:customViewAttribute="Hello world!"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment