Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:50:17+00:00 2026-06-18T00:50:17+00:00

I am using ActionBarSherlock: There are 3 menu items, of which only 1 has

  • 0

I am using ActionBarSherlock:

There are 3 menu items, of which only 1 has an ActionLayout.

default_menu.xml

<item
    android:id="@+id/searchIcon"
    android:icon="@drawable/search_icon"
    android:actionLayout="@layout/search_icon_actionview"
    android:showAsAction="always|collapseActionView"
    android:title="Search"/>
<item
    android:id="@+id/newIcon"
    android:icon="@drawable/new_icon"
    android:orderInCategory="0"
    android:showAsAction="ifRoom|collapseActionView"
    android:title="New"/>
<item
    android:id="@+id/notificationIcon"
    android:icon="@drawable/notification_icon"
    android:orderInCategory="0"
    android:showAsAction="ifRoom|collapseActionView"
    android:title="Notifications"/>

if i am using the above code. Only 1st 2 icons are visible. And if i make 2nd and 3rd as Always they remain even when the actionLayout is opened when clicked on Search.

I want to show all the 3 Menu Items initially and when search_icon is clicked hide every Item.

I also have a doubt about my implementation, whether i am doing i the right way.

In the Activity’s(which has a viewPager) first Fragment:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.searchIcon:

    mEtSearchbar.clearFocus();
    (new Handler()).postDelayed(new Runnable() {
       public void run() {
           mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
           mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
       }
    }, 100);

        return true;
    case R.id.newIcon:

        return true;
    case R.id.notificationIcon:

        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    inflater.inflate(R.menu.default_menu, menu);

    mSearchbar = (MenuItem) menu.findItem(R.id.searchIcon);
    View actionview = mSearchbar.getActionView();
    mEtSearchbar = ((EditText) actionview.findViewById(R.id.search_editText));
    ImageView searchImage = ((ImageView) actionview.findViewById(R.id.search_image));
    searchImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            String s = mEtSearchbar.getText().toString();
            Toast.makeText(getSherlockActivity(), "Searching for: " + s, Toast.LENGTH_SHORT)
                    .show();
        }
    });
    super.onCreateOptionsMenu(menu, inflater);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:50:18+00:00Added an answer on June 18, 2026 at 12:50 am

    This is what i ended up using.

     @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    
                super.onCreateOptionsMenu(menu);
                MenuInflater inflater = getSupportMenuInflater();
                inflater.inflate(R.menu.main, menu);
    
                MenuItem searchItem = menu.findItem(R.id.search);
    
                mSearchView = (SearchView) searchItem.getActionView();
                setupSearchView(searchItem);
    
                mSearchView.setOnSearchClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                // hide action item
                                if (menu != null) {
                                        menu.findItem(R.id.notifications).setVisible(false);
                                        menu.findItem(R.id.share).setVisible(false);
                                }
    
                        }
                });
                mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
                        @Override
                        public boolean onClose() {
                                adapter.getFilter().filter("");
                                // re-show the action button
                                if (menu != null) {
                                        menu.findItem(R.id.notifications).setVisible(true);
                                        menu.findItem(R.id.share).setVisible(true);
                                }
                                return false;
    
                        }
                });
                return true;
        }
    
    private void setupSearchView(MenuItem searchItem) {
             //code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone experience with a cropped title / label and ActionBarSherlock? Using <application android:name=WasserwegeApp
I'm using ActionBarSherlock. On Android 3.0+, there's a subtle shadow under the ActionBar. But
I am using ActionBarSherlock, and this XML line crashes in Android 2.x: android:layout_height=?android:attr/actionBarSize Is
I'm using ActionBarSherlock and have set an icon using android:logo in my theme. I'd
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I'm using ActionBarSherlock in my Android project, and it's awesome. One small issue: My
I set up a test app using ActionbarSherlock 4.0, which works fine in the
I'm using Android Support Library (v4) and ActionBarSherlock. I'm trying to close a progress
Context I am creating an action bar with some action items, using ActionbarSherlock. Some
I am using ActionBarSherlock on Android 4.0.3, so it might use the native ActionBar.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.