Example usage for android.view MenuItem setTitle

List of usage examples for android.view MenuItem setTitle

Introduction

In this page you can find the example usage for android.view MenuItem setTitle.

Prototype


public MenuItem setTitle(@StringRes int title);

Source Link

Document

Change the title associated with this item.

Usage

From source file:com.gh4a.activities.GistActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean authorized = Gh4Application.get().isAuthorized();

    MenuItem starAction = menu.findItem(R.id.star);
    starAction.setVisible(authorized);//ww w .  j ava2s .  c  om
    if (authorized) {
        if (mIsStarred == null) {
            MenuItemCompat.setActionView(starAction, R.layout.ab_loading);
            MenuItemCompat.expandActionView(starAction);
        } else if (mIsStarred) {
            starAction.setTitle(R.string.repo_unstar_action);
            starAction.setIcon(R.drawable.unstar);
        } else {
            starAction.setTitle(R.string.repo_star_action);
            starAction.setIcon(R.drawable.star);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:tv.acfun.video.DetailsActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.details, menu);
    if (mCookies != null)
        new Thread() {
            public void run() {
                isFaved = MemberUtils.checkFavourite(API.getDomainRoot(getApplicationContext()), mCookies,
                        mAcId);// w w  w .  ja v  a 2s  .  c om
                if (isFaved) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            MenuItem item = menu.findItem(R.id.action_fav);
                            item.setTitle("??");
                            item.setIcon(R.drawable.ic_action_favorited);
                        }
                    });
                }
            }
        }.start();
    mShareMenuItem = menu.findItem(R.id.action_share);
    if (mVideo != null)
        mShareMenuItem.setEnabled(true);
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.btmura.android.reddit.app.CommentListController.java

private void prepareAuthorActionItem(Menu menu, ListView lv, int pos) {
    String author = getAuthor(pos);
    MenuItem item = menu.findItem(R.id.menu_author);
    item.setVisible(MenuHelper.isUserItemVisible(author) && isCheckedCount(lv, 1));
    if (item.isVisible()) {
        item.setTitle(MenuHelper.getUserTitle(context, author));
    }/*w w  w .  ja  va  2 s. c om*/
}

From source file:com.keepassdroid.EntryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.entry, menu);

    MenuItem togglePassword = menu.findItem(R.id.menu_toggle_pass);
    if (mShowPassword) {
        togglePassword.setTitle(R.string.menu_hide_password);
    } else {/*  w  w w . jav a  2 s.c o m*/
        togglePassword.setTitle(R.string.menu_showpass);
    }

    MenuItem gotoUrl = menu.findItem(R.id.menu_goto_url);
    MenuItem copyUser = menu.findItem(R.id.menu_copy_user);
    MenuItem copyPass = menu.findItem(R.id.menu_copy_pass);

    // In API >= 11 onCreateOptionsMenu may be called before onCreate completes
    // so mEntry may not be set
    if (mEntry == null) {
        gotoUrl.setVisible(false);
        copyUser.setVisible(false);
        copyPass.setVisible(false);
    } else {
        String url = mEntry.getUrl();
        if (EmptyUtils.isNullOrEmpty(url)) {
            // disable button if url is not available
            gotoUrl.setVisible(false);
        }
        if (mEntry.getUsername().length() == 0) {
            // disable button if username is not available
            copyUser.setVisible(false);
        }
        if (mEntry.getPassword().length() == 0) {
            // disable button if password is not available
            copyPass.setVisible(false);
        }
    }

    return true;
}

From source file:com.example.android.pantry.scanner.BarcodeScannerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.menu_flash:
        mFlash = !mFlash;//from   www  .  java  2s.  co m
        if (mFlash) {
            item.setTitle(R.string.flash_on);
        } else {
            item.setTitle(R.string.flash_off);
        }
        mScannerView.setFlash(mFlash);
        return true;
    case R.id.menu_auto_focus:
        mAutoFocus = !mAutoFocus;
        if (mAutoFocus) {
            item.setTitle(R.string.auto_focus_on);
        } else {
            item.setTitle(R.string.auto_focus_off);
        }
        mScannerView.setAutoFocus(mAutoFocus);
        return true;
    case R.id.menu_formats:
        DialogFragment fragment = FormatSelectorDialogFragment.newInstance(this, mSelectedIndices);
        fragment.show(getSupportFragmentManager(), "format_selector");
        return true;
    case R.id.menu_camera_selector:
        mScannerView.stopCamera();
        DialogFragment cFragment = CameraSelectorDialogFragment.newInstance(this, mCameraId);
        cFragment.show(getSupportFragmentManager(), "camera_selector");
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.pockethub.android.ui.gist.GistFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean owner = isOwner();
    if (!owner) {
        menu.removeItem(R.id.m_delete);/*from   w  w  w . java2  s .co m*/
        MenuItem starItem = menu.findItem(R.id.m_star);
        starItem.setEnabled(loadFinished && !owner);
        if (starred) {
            starItem.setTitle(R.string.unstar);
        } else {
            starItem.setTitle(R.string.star);
        }
    } else {
        menu.removeItem(R.id.m_star);
    }
}

From source file:com.jbirdvegas.mgerrit.CardsFragment.java

private void setMenuItemTitle(MenuItem menuItem, String formatString, String parameters) {
    String title = String.format(formatString, parameters);
    menuItem.setTitle(title);
}

From source file:com.github.pockethub.ui.gist.GistFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean owner = isOwner();
    if (!owner) {
        menu.removeItem(R.id.m_delete);//from w  ww  . java 2 s . c  o m
        MenuItem starItem = menu.findItem(R.id.m_star);
        starItem.setEnabled(loadFinished && !owner);
        if (starred)
            starItem.setTitle(R.string.unstar);
        else
            starItem.setTitle(R.string.star);
    } else
        menu.removeItem(R.id.m_star);
}

From source file:org.melato.bus.android.activity.ScheduleActivity.java

private void updateAgency(MenuItem browse) {
    if (browse != null) {
        Agency agency = Info.routeManager(this).getAgency(activities.getRouteId());
        Drawable drawable = Info.getAgencyIcon(this, agency);
        if (drawable != null) {
            browse.setIcon(drawable);/*  w w  w  .ja v  a2s .c  o m*/
        }
        if (agency.getLabel() != null) {
            browse.setTitle(agency.getLabel());
        }
    }
}

From source file:net.kourlas.voipms_sms.activities.ConversationsActivity.java

/**
 * Switches between "mark as read" and "mark as unread" buttons for the action mode depending on which items in
 * the RecyclerView are selected./*w w w  .j  a v  a 2s  . c  o m*/
 */
private void updateButtons() {
    int read = 0;
    int unread = 0;
    for (int i = 0; i < adapter.getItemCount(); i++) {
        if (adapter.isItemChecked(i)) {
            if (adapter.getItem(i).isUnread()) {
                unread++;
            } else {
                read++;
            }
        }
    }

    MenuItem item = actionMode.getMenu().findItem(R.id.mark_read_unread_button);
    if (read > unread) {
        item.setIcon(R.drawable.ic_markunread_white_24dp);
        item.setTitle(R.string.conversations_action_mark_unread);
    } else {
        item.setIcon(R.drawable.ic_drafts_white_24dp);
        item.setTitle(R.string.conversations_action_mark_read);
    }
}