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:net.kourlas.voipms_sms.activities.NewConversationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        switch (item.getItemId()) {
        case R.id.keyboard_button:
            SearchView searchView = (SearchView) actionBar.getCustomView().findViewById(R.id.search_view);
            if (searchView.getInputType() == (InputType.TYPE_TEXT_VARIATION_PERSON_NAME)) {
                searchView.setInputType(InputType.TYPE_CLASS_PHONE);
                item.setIcon(R.drawable.ic_keyboard_white_24dp);
                item.setTitle(R.string.new_conversation_action_keyboard);
            } else {
                searchView.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
                item.setIcon(R.drawable.ic_dialpad_white_24dp);
                item.setTitle(R.string.new_conversation_action_dialpad);
            }/*  ww w . j  a va2  s .c o m*/
            return true;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.eugene.fithealthmaingit.MainActivity.java

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}

From source file:com.android.deskclock.worldclock.CitiesActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem sortMenuItem = menu.findItem(R.id.menu_item_sort);
    if (mSortType == SORT_BY_NAME) {
        sortMenuItem.setTitle(getString(R.string.menu_item_sort_by_gmt_offset));
    } else {/*  w  w  w .  ja va  2  s  .  c om*/
        sortMenuItem.setTitle(getString(R.string.menu_item_sort_by_name));
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:net.etuldan.sparss.fragment.EntryFragment.java

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

    if (mFavorite) {
        MenuItem item = menu.findItem(R.id.menu_star);
        item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star);
    }/*ww  w  . ja va  2s  .c o m*/
    MenuItem item = menu.findItem(R.id.menu_switch_full_original);
    item.setChecked(mPreferFullText);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.android.gallery3d2.ingest.IngestActivity.java

private void setSwitcherMenuState(MenuItem menuItem, boolean inFullscreenMode) {
    if (menuItem == null)
        return;/*from  w w  w.  jav a2 s.  c o m*/
    if (!inFullscreenMode) {
        menuItem.setIcon(android.R.drawable.ic_menu_zoom);
        menuItem.setTitle(R.string.switch_photo_fullscreen);
    } else {
        menuItem.setIcon(android.R.drawable.ic_dialog_dialer);
        menuItem.setTitle(R.string.switch_photo_grid);
    }
}

From source file:com.plined.liftlog.RoutineListFragment.java

protected void setSortMenuText(MenuItem item) {
    if (getSortModePref() == LiftLogDBAPI.ROUTINE_SORT_ALPHA) {
        item.setTitle("Sort by use date");
    } else {//from ww w  .j  a  v  a 2 s  .  c o m
        item.setTitle("Sort alphabetically");
    }
}

From source file:me.acristoffers.tracker.activities.PackageListActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_package_list, menu);

    MenuItem item = menu.findItem(R.id.toggle_inactive);

    final boolean showInactive = packageListFragment.isShowInactive();

    item.setTitle(showInactive ? R.string.hide_inactive : R.string.show_inactive);
    item.setIcon(showInactive ? R.drawable.ic_visibility_off_black_48dp : R.drawable.ic_visibility_black_48dp);

    item = menu.findItem(R.id.search);/*from   w ww .  j a  v a2s.com*/
    if (item != null) {
        final SearchView searchView = (SearchView) item.getActionView();
        if (searchView != null) {
            searchView.setQueryHint(getResources().getString(R.string.filter));

            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(final String query) {
                    filter(query);
                    return true;
                }

                @Override
                public boolean onQueryTextChange(final String newText) {
                    // Workaround this:
                    // http://stackoverflow.com/questions/9327826/searchviews-oncloselistener-doesnt-work/12975254#12975254
                    if (newText.isEmpty()) {
                        filter(null);
                    } else {
                        filter(newText);
                    }

                    return true;
                }
            });

            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    filter(null);
                    return true;
                }
            });
        }
    }

    return true;
}

From source file:org.mariotaku.twidere.activity.HomeActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    final boolean bottom_actions = mPreferences.getBoolean(PREFERENCE_KEY_COMPOSE_BUTTON, false);
    final boolean leftside_compose_button = mPreferences.getBoolean(PREFERENCE_KEY_LEFTSIDE_COMPOSE_BUTTON,
            false);/*  w  ww . jav a2s.  c o m*/
    int icon = R.drawable.ic_menu_tweet, title = R.string.compose;
    if (mViewPager != null && mAdapter != null) {
        final int position = mViewPager.getCurrentItem();
        final TabSpec tab = mAdapter.getTab(position);
        if (mShowAccountsTab && tab.position == Integer.MAX_VALUE) {
            icon = R.drawable.ic_menu_add;
            title = R.string.add_account;
        } else {
            title = R.string.compose;
            switch (tab.position) {
            case TAB_POSITION_MESSAGES:
                icon = R.drawable.ic_menu_compose;
                break;
            default:
                icon = R.drawable.ic_menu_tweet;
            }
        }

        final MenuItem composeItem = menu.findItem(MENU_COMPOSE);
        if (composeItem != null) {
            composeItem.setIcon(icon);
            composeItem.setTitle(title);
            composeItem.setVisible(!bottom_actions && mViewPager.getVisibility() == View.VISIBLE);
        }
        if (mComposeButton != null) {
            mComposeButton.setImageResource(icon);
            mComposeButton.setVisibility(
                    bottom_actions && mViewPager.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE);
            if (bottom_actions) {
                final FrameLayout.LayoutParams compose_lp = (FrameLayout.LayoutParams) mComposeButton
                        .getLayoutParams();
                compose_lp.gravity = Gravity.BOTTOM | (leftside_compose_button ? Gravity.LEFT : Gravity.RIGHT);
                mComposeButton.setLayoutParams(compose_lp);
            }
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.dycode.jepretstory.mediachooser.activity.BucketHomeFragmentActivity.java

private void setCurrentMode(MediaType mode) {
    currentMediaMode = mode;/*from  w w w  . ja va  2s .c  o m*/
    if (currentMediaMode == MediaType.IMAGE) {

        if (mMenu != null) {
            MenuItem item = mMenu.findItem(R.id.menuCamera);
            item.setTitle(getString(R.string.image));
            item.setIcon(R.drawable.selector_camera_button);
        }
        getActionBar().setTitle(getString(R.string.image));

    } else {

        if (mMenu != null) {
            MenuItem item = mMenu.findItem(R.id.menuCamera);
            item.setTitle(getString(R.string.video));
            item.setIcon(R.drawable.selector_video_button);
        }
        getActionBar().setTitle(getString(R.string.video));

    }
}

From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.animate_fold:
        animateFold();//w  w w.  jav a  2  s . com
        break;
    case R.id.toggle_orientation:
        mOrientation = (mOrientation == Orientation.HORIZONTAL) ? Orientation.VERTICAL : Orientation.HORIZONTAL;
        item.setTitle((mOrientation == Orientation.HORIZONTAL) ? R.string.vertical : R.string.horizontal);
        mTranslation = 0;
        mFoldLayout.setOrientation(mOrientation);
        break;
    case R.id.camera_feed:
        if (mTextureView != null) {
            mIsCameraFeed = !mIsCameraFeed;
            item.setTitle(mIsCameraFeed ? R.string.static_image : R.string.camera_feed);
            item.setChecked(mIsCameraFeed);
            if (mIsCameraFeed) {
                mFoldLayout.removeView(mImageView);
                mFoldLayout.addView(mTextureView,
                        new ViewGroup.LayoutParams(mFoldLayout.getWidth(), mFoldLayout.getHeight()));
            } else {
                mFoldLayout.removeView(mTextureView);
                mFoldLayout.addView(mImageView,
                        new ViewGroup.LayoutParams(mFoldLayout.getWidth(), mFoldLayout.getHeight()));
            }
            mTranslation = 0;
        }
        break;
    case R.id.sepia:
        mIsSepiaOn = !mIsSepiaOn;
        item.setChecked(!mIsSepiaOn);
        if (mIsSepiaOn && mFoldLayout.getFoldFactor() != 0) {
            setSepiaLayer(mFoldLayout.getChildAt(0), true);
        } else {
            setSepiaLayer(mFoldLayout.getChildAt(0), false);
        }
        break;
    default:
        break;

    }
    return super.onOptionsItemSelected(item);
}