why aren't menus pre-inflated for you?
Why aren't menus inflated automatically for you in Andr开发者_开发技巧oid, the way an Activity's layout is?
They are, just override like this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.YOUR_MENU_LAYOUT, menu);
return true;
}
EDIT, heres a sample xml, they go in /res/menu
<menu>
<item android:id="@+id/menu_sample"
android:title="Sample text"
android:icon="@drawable/ic_menu_sample"
/>
</menu>
You do explicitly inflate your activity layout with setContentView(R.layout.whatever)
. It doesn't have inflate in the name, but that (among a few other things) is what it does.
精彩评论