将菜单项设置为始终显示 + 图标

set menu item as to aways show + icon

我可以将其中一个 ActionBar 菜单项设置为图标并将其显示为 "showAsAction="always" 我得到的只是溢出菜单和按钮的标题而不是图标。我不明白我做错了什么?

这是 activity 中的代码:

public class RecipientsActivity extends ListActivity {
private static final String TAG = RecipientsActivity.class.getSimpleName();
protected List<ParseUser> mFriends;
protected ParseUser mCurrentUser;
protected MenuItem mSendMenuItem;
protected ParseRelation<ParseUser> mFriendsRelation;
@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipients);

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public void onResume() {
    super.onResume();

    mCurrentUser = ParseUser.getCurrentUser();
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
    setProgressBarIndeterminateVisibility(true);

    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    query.findInBackground(new FindCallback<ParseUser>() {
        @Override
        public void done(List<ParseUser> friends, ParseException e) {
            setProgressBarIndeterminateVisibility(false);
            if (e == null) {
                mFriends = friends;

                String[] friendNames = new String[mFriends.size()];
                int i = 0;
                for (ParseUser friend : mFriends) {
                    friendNames[i] = friend.getUsername();
                    i++;
                }

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(RecipientsActivity.this,
                        android.R.layout.simple_list_item_checked,
                        friendNames);
                setListAdapter(adapter);
            } else {
                Log.e(TAG, e.getMessage());
                AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
                //e.getMesssage = says useful information about the error
                builder.setMessage(e.getMessage());
                builder.setTitle(R.string.error_title);
                builder.setPositiveButton(android.R.string.ok, null);

                AlertDialog dialog = builder.create();
                dialog.show();
            }
        }
    });
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_recipients, menu);
    mSendMenuItem = menu.getItem(0);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_send) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mSendMenuItem.setVisible(true);

}

你的 activity 是 ListActivity。这意味着您使用的是操作栏的原生 API 级别 11+ 实现,而不是 appcompat-v7 向后移植。

因此,将 app:showAsAction 更改为 android:showAsAction