0

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

在此处输入图像描述

在此处输入图像描述

这是活动中的代码:

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);

}
4

1 回答 1

2

你的活动是ListActivity。这意味着您正在使用操作栏的本机 API 级别 11+ 实现,而不是appcompat-v7向后移植。

因此,更改app:showAsActionandroid:showAsAction

于 2015-05-30T22:49:21.780 回答