JakeWharton/ActionBarSherlock — Issue #193: Null background activity can not draw action bar items properly with invalidateOptionsMenu()
Author: bossturbo
Created: 2012-01-17 17:50:27+00:00
State: open

I found a drawing bug on the API 9 phone with ABS v4.0, beta 5.
Action bar Items are not drawn properly by calling the invalidateOptionsMenu().
This bug does not occur on the API 15 emulator without ABS.

Sample code is like this.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Set activity background to null
getWindow().setBackgroundDrawable(null);

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mItems++;
if (mItems>= 8) {
mItems = 0;
}
invalidateOptionsMenu();
}
});
}

public boolean onCreateOptionsMenu(Menu menu) {
for (int i = 0; i < mItems; i++) {
String title = String.format("Item: %d", i);
int iconId = (i % 2 == 0) ? R.drawable.ic_search : R.drawable.ic_refresh;
menu.add(title)
.setIcon(iconId)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
return super.onCreateOptionsMenu(menu);
}