android – Inflate ActionBarSherlock菜单以XML格式定义

android – Inflate ActionBarSherlock菜单以XML格式定义,第1张

概述应该足够简单但可能不是. 在Android 3.0中使用 *** 作栏时,您可以选择以XML或代码定义菜单项.我更喜欢在xml中对它们进行编码,因为动作条感觉基于UI而不是功能. 平均每天,您可以使用它将xml扩展到菜单中 @Overridepublic boolean onCreateOptionsMenu(Menu menu){ // Menu is defined inside 'res 应该足够简单但可能不是.

在Android 3.0中使用 *** 作栏时,您可以选择以XML或代码定义菜单项.我更喜欢在xml中对它们进行编码,因为动作条感觉基于UI而不是功能.

平均每天,您可以使用它将xml扩展到菜单中

@OverrIDepublic boolean onCreateOptionsMenu(Menu menu){    // Menu is defined insIDe 'res/menu/...xml    getMenuInflater().inflate(R.menu.activity_home,menu);    return true;}

你的XML文件看起来像这样

<menu xmlns:androID="http://schemas.androID.com/apk/res/androID" >    <item        androID:ID="@+ID/menu_settings"        androID:orderIncategory="100"        androID:showAsAction="never"        androID:title="@string/menu_settings"/>    <item        androID:ID="@+ID/menu_item_menu"        androID:icon="@drawable/menu_off_128"        androID:showAsAction="ifRoom|withText"        androID:title="@string/inBox_string"/>    <item        androID:ID="@+ID/menu_item_gallery"        androID:icon="@drawable/gallery_off_128"        androID:showAsAction="ifRoom|withText"        androID:title="@string/gallery_string"/>    <item        androID:ID="@+ID/menu_item_inBox"        androID:icon="@drawable/inBox_off_128"        androID:showAsAction="ifRoom|withText"        androID:title="@string/inBox_string"/>    <item        androID:ID="@+ID/menu_item_contact"        androID:icon="@drawable/phone_off_128"        androID:showAsAction="ifRoom|withText"        androID:title="@string/contact_string"/></menu>

现在,我遇到了使 *** 作栏向后兼容的问题,而actionbarsherlock似乎是最令人愉快的使用和流行.
所以我用actionbarsherlock尝试了上面的内容,遗憾的是有编译时问题.

即,inflater返回的Menu类来自’AndroID.vIEw.menu’而不是’com.actionbarsherlock.menu’.我在github上挖掘了样本,但是所有这些都在代码中定义了菜单.

那么有没有人想要使用基于XML文件的布局的actionbarsherlock菜单?

解决方法 试试这个
@OverrIDe    public boolean onCreateOptionsMenu(com.actionbarsherlock.vIEw.Menu menu) {        getSupportMenuInflater().inflate(R.menu.your_menu,menu);        return true;}
总结

以上是内存溢出为你收集整理的android – Inflate ActionBarSherlock菜单以XML格式定义全部内容,希望文章能够帮你解决android – Inflate ActionBarSherlock菜单以XML格式定义所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1137895.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存