开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜