Ich versuche, meiner Support-Aktionsleiste einige Aktionselemente hinzuzufügen. In meiner Aktivität habe ich auch Registerkarten zur Aktionsleiste hinzugefügt.Aktionselemente, die in ActionBar nicht angezeigt werden mit showAsAction = "ifRoom"
Dies ist ein Auszug aus der Aktivität:
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);
}
}
Die Klasse LoadTabsInBackground
einige Registerkarten auf die ActionBar fügt, nachdem er einige Datenbankoperation zu tun.
Dies ist die Menüressource Ich aufblasen:
<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>
Und hier ist ein Auszug aus AndroidManifest.xml, in dem Sie das Thema sse kann ich benutze ist 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>
Alles scheint mir korrekt zu sein, obwohl Tabs korrekt geladen sind, bedeutet das, dass ActionBar richtig funktioniert, keiner der Menüpunkte ist in der Aktionsleiste geladen. Wenn Sie den Wert showAsAction
auf always
setzen, ändert sich nichts.
Ich teste es auf Android 2.3.3.
möglich Duplikat [ActionBar nicht mit AppCompat gezeigt] (http: // Stackoverflow. com/questions/18510337/actionbar-nicht-gezeigt-mit-appcompat) – flx