安卓:图标不显示在操作栏 [英] Android: Icons don't appear in Action Bar

查看:326
本文介绍了安卓:图标不显示在操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的教程谷歌的行动吧,但图标不显示就可以了,这是菜单的xml文件:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:yourapp =htt​​p://schemas.android.com/apk/res-auto>
    <项目机器人:ID =@ + ID / action_refresh
          机器人:图标=@可绘制/ ic_action_refresh
          机器人:标题=刷新
          机器人:showAsAction =ifRoom/>
    <项目机器人:ID =@ + ID / action_settings
          机器人:图标=@可绘制/ ic_action_settings
          机器人:标题=设置
          机器人:showAsAction =ifRoom/>
     <项目机器人:ID =@ + ID / action_compose
          机器人:图标=@可绘制/ ic_action_new
          机器人:标题=添加
          机器人:showAsAction =ifRoom/>
< /菜单>
 

这在我的主acivity:

  @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气操作栏中使用的菜单项
        MenuInflater充气= getMenuInflater();
        inflater.inflate(R.menu.main_activity_bar,菜单);
        返回super.onCreateOptionsMenu(菜单);
    }
 

解决方案

使用 yourapp:showAsAction 而不是安卓showAsAction
并确保您的活动扩展 ActionBarActivity 从compat的lib目录

I'm following the google tutorial for action bars but the icons don't appear on it, this is the menu xml file:

<menu   xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_refresh"
          android:icon="@drawable/ic_action_refresh"
          android:title="refresh"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/action_settings"
          android:icon="@drawable/ic_action_settings"
          android:title="settings"
          android:showAsAction="ifRoom"/>
     <item android:id="@+id/action_compose"
          android:icon="@drawable/ic_action_new"
          android:title="add"
          android:showAsAction="ifRoom"/>
</menu>

and this in my main acivity:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_activity_bar, menu);
        return super.onCreateOptionsMenu(menu);
    }

解决方案

Use yourapp:showAsAction instead of android:showAsAction
And make sure your Activity extends ActionBarActivity from the compat lib

这篇关于安卓:图标不显示在操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆