行动项目没有出现在动作条与showAsAction =" ifRoom"
我想一些行动项目添加到我的支持行动吧。在我的活动,我也卡加入到行动吧。
I'm trying to add some Action Items to my Support Action Bar. In my activity, I have also tabs added to the Action Bar.
这是该活动的一个片段:
This is an excerpt of the activity:
public class ShowEmails extends ActionBarActivity implements ShowEmailsFragmentInteractionListener {
private IMAPClientService service;
private boolean bound;
private ActionBar ab;
private MailDBHelper mdbhelper;
private SQLiteDatabase db;
private Intent client_service;
<.........................>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.client_service = new Intent(this, IMAPClientService.class);
this.mdbhelper = new MailDBHelper(this.getApplicationContext(), MailDBHelper.MAIL_DB_NAME, null, MailDBHelper.MAIL_DB_VERSION);
this.db = this.mdbhelper.openWriteable();
this.ab = this.getSupportActionBar();
this.ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
this.ab.show();
Tab t = ab.newTab().setText(R.string.all_emails)
.setTabListener(new TabListener<ShowEmailsFragment>(this, "all", ShowEmailsFragment.class));
ab.addTab(t);
new LoadTabsInBackground().execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show_emails_bulk_action, menu);
return super.onCreateOptionsMenu(menu);
}
}
类 LoadTabsInBackground
做一些数据库的操作后,增加了一些标签的动作条。
The class LoadTabsInBackground
adds some tabs to the ActionBar after doing some database operation.
这是菜单资源我膨胀:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/email_refresh"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="@string/action_refresh"
android:icon="@drawable/ic_menu_refresh"/>
<item
android:id="@+id/email_bulk_seen"
android:orderInCategory="20"
android:showAsAction="ifRoom"
android:title="@string/action_seen"
android:icon="@android:drawable/sym_action_email"/>
<item
android:id="@+id/email_bulk_delete"
android:orderInCategory="40"
android:showAsAction="ifRoom"
android:title="@string/action_delete"
android:icon="@android:drawable/ic_menu_delete"/>
</menu>
这里是AndroidManifest.xml中,摘录在这里你可以SSE我使用的主题为 Theme.AppCompat.Light
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.dndonline.battleclient4android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" >
<.......................>
<activity
android:name="it.dndonline.battleclient4android.Activities.ShowEmails"
android:label="@string/title_activity_show_folders"
android:theme="@style/Theme.AppCompat.Light" >
</activity>
<......................................>
</application>
</manifest>
一切似乎是正确的我,不幸的是,尽管被正确加载标签,这意味着动作条的正常工作,没有一个菜单项的操作栏中的加载。在 showAsAction
值设置为总是
不会改变任何东西。
Everything seems correct to me, unfortunately, although tabs are loaded correctly, this means that ActionBar is properly working, none of the menu items are loaded in the action bar. Setting the showAsAction
value to always
doesn't change anything.
我在Android 2.3.3测试。
I'm testing it on Android 2.3.3.
我发现这个问题。有一个在菜单.xml文件错误。事实上,我添加了一个新的命名空间:
I found the problem. There was an error in the menu .xml file. In fact, I've added a new namespace:
的xmlns:程序=http://schemas.android.com/apk/res-auto
不过,我仍然会参考属性,如果它属于机器人
命名空间:
But then, I still refer the property as if it belongs to the android
namespace:
安卓showAsAction =ifRoom
正确的方法将这一属性是使用:
The right way to refer this property is to use:
应用程序:showAsAction =ifRoom
因为它属于命名空间应用
。
下面是在文档中的相关部分:
Here is the relevant part in documentation:
如果您的应用程序使用的是支持库的版本兼容 低到了Android 2.1,该showAsAction属性不可用 从Android:名称空间。代替这个属性由提供 支持库,你必须定义自己的XML命名空间和使用 该命名空间作为属性preFIX。 (自定义XML命名空间应该 根据您的应用程序的名称是,但它可以是你想要的,只是任何名称 在声明它的文件范围之内到达。)
If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.)