iBEK
iBEK

Reputation: 642

How to move the Search View to left side of screen?

I want my search view to be on left side of screen but can't figure out how to move it. code is in menu_main.xml file shown below.

I've looked on StackOverflow and the solutions from the following didn't work for me: How to move SearchView 's search Icon to the right side?

enter image description here

Also, I coded in my MainActivity java file:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(menu_main, menu);

  MenuInflater inflater= getMenuInflater();
  inflater.inflate(R.menu.menu_main, menu);
  MenuItem item= menu.findItem(R.id.menuSearch);
  SearchView searchView = (SearchView) item.getActionView();
  searchView.setLayoutParams(new ActionBar.LayoutParams(Gravity.START));

  return true;
}

The above code also does nothing to move the search view to left side of ActionBar.

Upvotes: 1

Views: 446

Answers (1)

Sandeep Manmode
Sandeep Manmode

Reputation: 395

Remove the icon from the menu_main.xml file

You can try this:

   final ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.ic_search);

Hope this helps you.

Upvotes: 1

Related Questions