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.octade.droid.ilesansfil.IleSansFil.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_LOCATION:
        if (item.isChecked() == false) {
            item.setChecked(true);/*from www  .  j av  a 2 s  .  c o  m*/
            item.setTitle(getResources().getString(R.string.menuGpsOn));
            mainApp.getMapView().setLocationDetection(true);

        } else {
            item.setChecked(false);
            item.setTitle(getResources().getString(R.string.menuGpsOff));
            mainApp.getMapView().setLocationDetection(false);
        }
        return true;
    case MENU_SETTINGS:

        return true;
    case MENU_ABOUT:
        about();
        return true;
    case MENU_TOGGLE_PIN:
        if (mainApp.getMapView().togglePins() == true) {
            item.setChecked(true);
            item.setTitle(getResources().getString(R.string.menuPinOn));
        } else {
            item.setChecked(false);
            item.setTitle(getResources().getString(R.string.menuPinOff));
        }

        return true;
    }
    return false;
}

From source file:ng.uavp.ch.ngusbterminal.MainActivity.java

@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();
    switch (id) {
    case R.id.menu_settings: {
        ShowTab(TAB_CONNECT);/*  ww w.  j  ava2  s. co m*/
        return true;
    }

    case R.id.menu_exit: {
        finish();
        return true;
    }

    case R.id.menu_readfile: {
        readFile();
        return true;
    }

    case R.id.menu_writefile: {
        if (logtofile.isActive()) {
            logtofile.StopLoggingToFile();
            MenuItem itemwf = menu.findItem(R.id.menu_writefile);
            itemwf.setTitle(R.string.action_start_log);
            itemwf.setIcon(R.drawable.ic_doc_save);
        } else {
            writeFile();

        }
        return true;
    }

    case R.id.menu_clear: {
        ShellFragment.TerminalEditText tet = (ShellFragment.TerminalEditText) findViewById(R.id.editText1);
        if (tet != null)
            tet.setText("");
        else
            ShowTab(TAB_SHELL);
        return true;
    }

    case R.id.menu_about: {
        ShowTab(TAB_ABOUT);
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.galgame.august.MainDrawerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem item = menu.findItem(R.id.action_dark_mode);
    boolean isNight = SPUtils.isNight(this);
    if (isNight) {
        item.setTitle("?");
    }// w w  w .j av a  2 s.co  m
    return true;
}

From source file:com.jecelyin.android.file_explorer.FileExplorerAction.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_all) {
        if (!item.isChecked()) {
            view.setSelectAll(true);/*from   w w w .java2 s  .  co m*/
            item.setChecked(true);
            item.setTitle(R.string.cancel_select_all);
        } else {
            view.setSelectAll(false);
        }
    } else if (id == R.id.copy && !checkedList.isEmpty()) {
        fileClipboard.setData(true, checkedList);
        destroyActionMode();
    } else if (id == R.id.cut && !checkedList.isEmpty()) {
        fileClipboard.setData(false, checkedList);
        destroyActionMode();
    } else if (id == R.id.paste) {
        destroyActionMode();
        fileClipboard.paste(explorerContext.getCurrentDirectory());
    } else if (id == R.id.rename) {
        doRenameAction();
    } else if (id == R.id.share) {
        shareFile();
    } else if (id == R.id.delete) {
        doDeleteAction();
    } else {
        return false;
    }
    return true;
}

From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_display, menu);

    boolean paused = ConnectionTools.get().isPaused();
    MenuItem item = menu.findItem(R.id.menu_action_display_pause);
    item.setIcon(paused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp);
    item.setTitle(paused ? R.string.action_resume : R.string.action_pause);

    item.setEnabled(isConnected);/*from   w w  w .ja v a2s  .  c  om*/
    item.setVisible(isConnected);
}

From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.sessions_context, menu);
    MenuItem starMenuItem = menu.findItem(R.id.menu_star);
    starMenuItem.setTitle(R.string.description_remove_schedule);
    starMenuItem.setIcon(R.drawable.ic_action_remove_schedule);
    return true;//  w ww  .j av  a2  s .com
}

From source file:com.vaquerosisd.projectmanager.TaskList.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (taskSelected)
        menu.findItem(R.id.actionBar_DeleteTaskIcon).setVisible(true);
    else//from ww  w.j a  v a2s .  c om
        menu.findItem(R.id.actionBar_DeleteTaskIcon).setVisible(false);

    if (searching) {
        getActionBar().setDisplayShowTitleEnabled(false);
        menu.findItem(R.id.actionBar_SearchTaskIcon).setVisible(false);
        menu.findItem(R.id.actionBar_SearchTaskItem).setVisible(true);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    } else {
        getActionBar().setDisplayShowTitleEnabled(true);
        MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
        final EditText searchProject = (EditText) searchItem.getActionView()
                .findViewById(R.id.actionBar_SearchItemEditText);
        searchProject.setText("");
        menu.findItem(R.id.actionBar_SearchTaskIcon).setVisible(true);
        menu.findItem(R.id.actionBar_SearchTaskItem).setVisible(false);
    }

    MenuItem logMenuItem = menu.findItem(R.id.actionBar_Menu_user);
    if (currentUser != null) {
        logMenuItem.setTitle("Log Out from " + currentUser.getUsername());
    } else {
        checkUser();
    }

    return true;
}

From source file:org.cirdles.chroni.AliquotMenuActivity.java

/**
 * The purpose of overriding this method is to alter/delete some of the menu items from the default
 * menu, as they are not wanted in this Activity. Doing so prevents the unnecessary stacking of
 * Activities by making the user follow the intended flow of Activities in the application.
 *
 * @param menu the menu that has been inflated in the Activity
 * @return true so that the menu is displayed
 *//* w w  w .j  a v  a 2s . c  o  m*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // removes the History item from the menu
    MenuItem historyItem = menu.findItem(R.id.historyMenu);
    historyItem.setVisible(false);

    // removes the Edit Credentials item from the menu
    MenuItem credentialsItem = menu.findItem(R.id.editProfileMenu);
    credentialsItem.setVisible(false);

    MenuItem viewFiles = menu.findItem(R.id.viewFilesMenu);
    viewFiles.setVisible(false);

    // if coming from a Table Activity, changes Main Menu item to say "Back to Table"
    if (getIntent().hasExtra("From_Table")) {
        if (getIntent().getStringExtra("From_Table").equals("true")) {
            MenuItem backItem = menu.findItem(R.id.returnToMenu);
            backItem.setTitle("Back to Table");
        }
    }

    return true;
}

From source file:org.jamienicol.episodes.ShowActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    final MenuItem toggleStarred = menu.findItem(R.id.menu_toggle_show_starred);
    if (isShowStarred) {
        toggleStarred.setIcon(R.drawable.ic_show_starred);
        toggleStarred.setTitle(R.string.menu_unstar_show);
    } else {/*from ww  w .j  a  va  2  s  . co  m*/
        toggleStarred.setIcon(R.drawable.ic_show_unstarred);
        toggleStarred.setTitle(R.string.menu_star_show);
    }

    final MenuItem toggleArchived = menu.findItem(R.id.menu_toggle_show_archived);
    if (isShowArchived) {
        toggleArchived.setIcon(R.drawable.ic_shows_list_archived);
        toggleArchived.setTitle(R.string.menu_unarchive_show);
    } else {
        toggleArchived.setIcon(R.drawable.ic_shows_list_unarchived);
        toggleArchived.setTitle(R.string.menu_archive_show);
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = FontCache.getTypeface("Nunito-SemiBold.ttf", mActivity);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}