将菜单项设置为远离show + icon

时间:2015-05-30 22:39:09

标签: android menu menuitem overflow-menu

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

enter image description here

enter image description here

这是活动中的代码:

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

}

1 个答案:

答案 0 :(得分:2)

您的活动是ListActivity。这意味着您正在使用操作栏的本机API Level 11+实现,而不是appcompat-v7反向端口。

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