I have some weird behavior in the contextual action bar.
Firstly:
One menu item is only shown every second time I click on the overflow button:
Secondly / thirdly:
Is there a way that the icons do not use so much space?
When I change add property android:showAsAction="always"
to all items, there is actually enough space to show all icons - but my share icon is not clickable anymore:
Clean Project does not help.
I use Android 4.2.2 on my test device (Galaxy S3).
I even tried to completely flash a new ROM on my XXX GS3 (CyanogenMod 10.1 now, before SlimBean, also removed the navigationbar at at the bottom) - did not help.
I also tried it on a Nexus 4. There is more space, so the share button and the delete button are visible. The share button is not clickable when I start action mode, but when I turn the device to landscape mode it works, and when I turn it back to portrait it still works. So basicially on the Nexus 4, the share button does not work before rotating.
Manifest:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
Compiling against minSdkVersion=17
makes no difference.
I start the Action Mode from a fragment like this:
mActionMode = activity.startActionMode(mMultipleCallback);
In the ActionMode.Callback
I populate the menu:
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.management_cab, menu);
MenuItem item = menu.findItem(R.id.managementCABShare);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
//...other stuff
return true;
}
And here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:title="@string/checkAll"
android:id="@+id/managementCABCheckAll"
android:icon="@android:drawable/checkbox_on_background">
</item>
<item
android:title="@string/enable"
android:id="@+id/managementCABEnable"
android:icon="@drawable/sphere_green">
</item>
<item
android:title="@string/disable"
android:id="@+id/managementCABDisable"
android:icon="@drawable/sphere_red">
</item>
<item
android:title="@string/delete"
android:id="@+id/managementCABDelete"
android:icon="@android:drawable/ic_menu_close_clear_cancel">
</item>
<item
android:title="@string/share"
android:id="@+id/managementCABShare"
android:actionProviderClass="android.widget.ShareActionProvider"
android:icon="@android:drawable/ic_menu_share">
</item>
<item
android:title="@string/export"
android:id="@+id/managementCABExport"
android:icon="@drawable/explorer">
</item>
</menu>
For the sake of completeness the whole callback
:
protected ActionMode.Callback mMultipleCallback = new ActionMode.Callback() {
private ShareActionProvider mShareActionProvider;
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.management_cab, menu);
MenuItem item = menu.findItem(R.id.managementCABShare);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
hideUnwantedCABItems(menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
List<Integer> checkedPositions = getAllCheckedPositions();
switch (item.getItemId()) {
case R.id.managementCABCheckAll:
changeCheckedOfAllItems(true);
return true;
case R.id.managementCABEnable:
changeEnabled(checkedPositions, true);
return true;
case R.id.managementCABDisable:
changeEnabled(checkedPositions, false);
return true;
case R.id.managementCABDelete:
if (deleteAlert == null)
createDeleteDialog(checkedPositions);
initDeleteDialog(checkedPositions);
return true;
case R.id.managementCABShare:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, exportItemsAndGetUris(checkedPositions));
shareIntent.setType("application/xml");
setShareIntent(shareIntent);
return true;
case R.id.managementCABExport:
String message;
if (StorageController.copyUriListToExportFolder(exportItemsAndGetUris(checkedPositions)))
message = getActivity().getString(R.string.export_success);
else
message = getActivity().getString(R.string.export_fail);
Toast.makeText(getActivity(), message + ":\n" + StorageController.getExternalExportApplicationFolder(), Toast.LENGTH_LONG).show();
return true;
default:
return false;
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
changeCheckedOfAllItems(false);
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
};