android通过xml来定义menu,Android通过XML来定义Menu

利用LayoutInflater infalter = getLayoutInflater();从XML文件中获取Layout的样式。在Menu中也可以采用类似的方式。我们在onCreateOptionsMenu()中如下处理:

public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater menuInflater = new MenuInflater(getApplication());

menuInflater.inflate(R.menu.chapter11_menu, menu);

return super.onCreateOptionsMenu(menu);

}

其中我们在res/menu目录下面创建Menu的xml文件chapter11_menu.xml。我们通过下面的例子看看Menu XML文件如何编写:

android:title="Close"

android:orderInCategory = "3"

android:icon="@drawable/android_focused" />

android:orderInCategory = "2"

android:title = "Sans Icon" />

android:orderInCategory="4"

android:enabled="false"

android:title="Disabled" />

android:menuCategory="secondary"

android:checkableBehavior="single"

android:visible="false" >

android:orderInCategory="0"

android:title="2nd-To-Last" />

android:orderInCategory="5"

android:title="Last" />

android:orderInCategory="3"

android:title="A submenu" >

android:title="Non-Ghost"

android:visible="true"

android:alphabeticShortcut="n" />

android:title="Ghost"

android:visible="true"

android:alphabeticShortcut="g" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值