[英]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.
代码在如下所示的 menu_main.xml 文件中。
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?我查看了 StackOverflow 并且以下解决方案对我不起作用: 如何将 SearchView 的搜索图标移动到右侧?
Also, I coded in my MainActivity java file:另外,我在我的 MainActivity java 文件中编码:
@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.上面的代码也没有将搜索视图移动到 ActionBar 的左侧。
Remove the icon from the menu_main.xml file从 menu_main.xml 文件中删除图标
You can try this:你可以试试这个:
final ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_search);
Hope this helps you.希望这对你有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.