Example usage for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

List of usage examples for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

Introduction

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

Prototype

int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

To view the source code for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

Click Source Link

Document

This item's action view collapses to a normal menu item.

Usage

From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java

void configureActionBarSearchView(Menu menu) {

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();

    searchItem.setShowAsActionFlags(/*from  w w  w. ja  v  a2  s. c om*/
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);

            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(View.GONE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(View.GONE);
            }

            if (!hasFocus) {
                if (mCurrentComposeFragment == mComposeDirectMessageFragment) {
                    if (mComposeDirectMessageView != null) {
                        mComposeDirectMessageView.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (mComposeTweetView != null) {
                        mComposeTweetView.setVisibility(View.VISIBLE);
                    }
                }
            }

            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    searchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    searchView.setOnFocusChangeListener(onFocusChangeListener);
}