简体   繁体   中英

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?

在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM