0

I'm kind of new to Android development and I'm creating an activity which have both top and bottom menu. I followed this which is to split the old action bar as the bottom menu, and use a custom view as the top menu. It works fine but with a little question.

I put a SearchView in the CustomView and I want do some styling to it. First is to expand it automatically when starting. But I don't know where to get my SearchView object, I tried find it in onCreateOptionsMenu, but get a null pointer:

public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.bottom_menu, menu);

        MenuItem searchMenuItem = menu.findItem(R.id.searchView);
        searchMenuItem.expandActionView();    //null !!
        return true;
    }

I have only one activity and I inflate the custom view in onCreate method:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        View view = View.inflate(getApplicationContext(), R.layout.top_menu_view, null);

        actionBar.setCustomView(view);
    }
}

Shall I find the SearchView object when inflating it?

Or do you have some other advice for a fixed search view?

Thanks:)

Community
  • 1
  • 1
MagicFingr
  • 479
  • 6
  • 20

1 Answers1

0

A really silly question,

View view = View.inflate(getApplicationContext(), R.layout.top_menu_view, null);
SearchView searchView = (SearchView) view.findViewById(R.id.searchView_main);

that's the thing I'm trying to find...

MagicFingr
  • 479
  • 6
  • 20