没能获得溢出功能的动作条中的android没能、动作、功能、android

2023-09-12 03:35:27 作者:6.不解风情的老妖怪

我的code ::

actionbar_sort_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/searchID"
        android:icon="@drawable/ic_action_search"
        android:showAsAction="ifRoom|withText"
        android:title="Search"/>
    <item
        android:id="@+id/featuredID"
        android:icon="@drawable/ic_action_featured"
        android:showAsAction="ifRoom|withText"
        android:title="Featured"/>
    <item
        android:id="@+id/dealsID"
        android:icon="@drawable/ic_action_deal"
        android:showAsAction="ifRoom|withText"
        android:title="Deals"
        />
    <item
        android:id="@+id/inviteID"
        android:icon="@drawable/ic_action_share"
        android:showAsAction="ifRoom|withText"
        android:title="Invite or Share"/>

</menu>

清单code ::

<application
        android:name="com.myApp.utilities.AppController"
        android:configChanges="orientation|keyboardHidden"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

主题我使用 ::

android:Theme.Holo

支持库 ::

android-support-v4.jar

{编辑}

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
   xmlns:yourapp="http://schemas.android.com/apk/res-auto"  >

    <item
        android:id="@+id/searchID"
        android:icon="@drawable/ic_action_search"
        yourapp:showAsAction="never"
        android:title="Search"/>
    <item
        android:id="@+id/featuredID"
        android:icon="@drawable/ic_action_featured"
        yourapp:showAsAction="never"
        android:title="Featured"/>
    <item
        android:id="@+id/dealsID"
        android:icon="@drawable/ic_action_deal"
        yourapp:showAsAction="never"
        android:title="Deals"
        />
    <item
        android:id="@+id/inviteID"
        android:icon="@drawable/ic_action_share"
        yourapp:showAsAction="never"
        android:title="Invite or Share"/>

</menu>

错误我收到

没有在包中com.myApp发现属性showAsAction'资源标识符

No resource identifier found for attribute 'showAsAction' in package com.myApp

推荐答案

由于您使用的是你需要有自己的名称空间preFIX支持库

Since you are using Support library you need to have your own namespace prefix

 <menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

然后改变这

  android:showAsAction="ifRoom|withText"

  yourapp:showAsAction="ifRoom|withText"

注:如果没有足够的空间显示在动作条的项目将出现在溢出菜单。如果你有空间,一些项目也出现在动作条,其余的溢出。

Note : If there is not enough space to display items in the actionbar it will appear in the overflow menu. If you have room for few items it appears on the actionbar and the rest in overflow.

编辑:

yourapp:showAsAction="never" 

从文档

http://developer.android.com/guide/topics/资源/菜单resource.html

 never  Never place this item in the Action Bar.