Created
June 15, 2019 19:27
-
-
Save B0yma/ebc681e503ea1fe11925729b31909e2c to your computer and use it in GitHub Desktop.
Binding Adapter Creating
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
//in manifest | |
apply plugin: 'kotlin-kapt' | |
... | |
dataBinding { enabled = true } | |
//------------------- | |
//Binding adapter example in kotlin | |
@BindingAdapter("app:backgroundTintAdapt") | |
fun setBackgroundTint(view: View, @ColorRes color: Int?) { | |
color?.let { | |
ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(it)) | |
} | |
} | |
//Binding adapter example in java | |
@BindingAdapter("app:setBckgrnd") | |
public static void setFabBckgrnd(View view, @ColorRes int hex) { | |
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(fab.getContext(), hex))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment