AndroidAnnotations and Material Design App Bar/ActionBar

I was trying to get the material design App Bar/ActionBar/Toolbar working with an activity that uses AndroidAnnotations. I was following the tutorial here but I was finding that while the bar was rendering, it didn’t have any content.

It turns out the culprit was AndroidAnnotations which was overwriting the content view after the toolbar was bound to it in the onCreate method.

The solution is to add a method with an @AfterViews annotation that will be run after the views are bound. For example:

@ViewById(R.id.toolbar)
Toolbar toolbar;

@AfterViews
protected void bindActionBar() {
    setSupportActionBar(toolbar);
}