What i am trying to do
::
What is happening
::
我的代码 ::
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>
清单代码 ::
<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>
错误我正在
找不到属性&#39; showAsAction&#39;的资源标识符。在com.myApp包中
答案 0 :(得分:0)
由于您使用的是支持库,因此您需要拥有自己的名称空间前缀
<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"
注意:如果没有足够的空间显示操作栏中的项目,它将显示在溢出菜单中。如果你有几个项目的空间,它会出现在操作栏上,其余项目会溢出。
编辑:
yourapp:showAsAction="never"
来自文档
http://developer.android.com/guide/topics/resources/menu-resource.html
never Never place this item in the Action Bar.
答案 1 :(得分:0)
我在移动设备上测试的原因是::“设备有一个菜单按钮,溢出图标不显示。”
代码 ::
@Override
public boolean onOptionsItemSelected(MenuItem item) {
ft = getFragmentManager().beginTransaction();
switch(item.getItemId()) {
case R.id.descriptionID:
onItemChangeBackground(1);
Fragment fragContents = FrgBufDetails.newInstance(buf_off_id);
ft.replace(R.id.content_frame, fragContents);
ft.addToBackStack(null);
ft.commit();
return true;
case R.id.MapID:
onItemChangeBackground(2);
Fragment fragMap = FrgBufLocation.newInstance(buf_off_id);
ft.replace(R.id.content_frame, fragMap);
ft.addToBackStack(null);
ft.commit();
return true;
case R.id.galleryID:
onItemChangeBackground(3);
Fragment fragGallery = FrgBufGallery.newInstance(buf_off_id);
ft.replace(R.id.content_frame, fragGallery);
ft.addToBackStack(null);
ft.commit();
return true;
case R.id.inviteID:
onItemChangeBackground(4);
View title = (View) getActivity()
.findViewById(R.id.inviteID);
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(getActivity(), title);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.actionbar_sort_menu, popup.getMenu());
popup.show();//showing popup menu
return true;
}
return super.onOptionsItemSelected(item);
}