Search code examples
androidandroid-databinding

Is there a support annotation to denote binding resources?


@LayoutRes denotes a layout resource (R.layout.myLayout), @ColorRes a color resource (R.color.colorPrimary), and so on. Is there any Android support annotation that denotes a binding resource (BR.myVar)?


Solution

  • Data binding is a relatively new feature, and there is no specific annotation for its resources yet. However, you can use @AnyRes as a substitute for now.

    See annotation docs:

    Use @AnyRes to indicate that the annotated parameter can be any type of R resource.

    and AnyRes docs:

    public interface AnyRes extends annotation.Annotation

    Denotes that an integer parameter, field or method return value is expected to be a resource reference of any type. If the specific type is known, use one of the more specific annotations instead, such as StringRes or DrawableRes.