Skip to content

Instantly share code, notes, and snippets.

@B0yma
Created June 15, 2019 19:27
Show Gist options
  • Save B0yma/ebc681e503ea1fe11925729b31909e2c to your computer and use it in GitHub Desktop.
Save B0yma/ebc681e503ea1fe11925729b31909e2c to your computer and use it in GitHub Desktop.
Binding Adapter Creating
//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