Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ButterKnife - bind drawable resource

How to eliminate the following initialization code using ButterKnife annotations?

private Drawable mExpandDrawable;
private Drawable mCollapseDrawable;

void init() {
    mExpandDrawable = getResources().getDrawable(R.drawable.ic_expand_small_holo_light);
    mCollapseDrawable = getResources().getDrawable(R.drawable.ic_collapse_small_holo_light);
}
like image 237
naXa Avatar asked Jan 20 '26 15:01

naXa


1 Answers

Use @BindDrawable from ButterKnife 7 API.

import butterknife.BindDrawable;

@BindDrawable(R.drawable.ic_expand_small_holo_light)
protected Drawable mExpandDrawable;
@BindDrawable(R.drawable.ic_collapse_small_holo_light)
protected Drawable mCollapseDrawable;

void init() {
    ButterKnife.bind(this);
}

There are @BindString, @BindInt, @BindDimen, @BindColor, @BindBool for other resource types.

like image 110
naXa Avatar answered Jan 23 '26 05:01

naXa