简体   繁体   English

如何将搜索视图移动到屏幕左侧?

[英]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.

相关问题 屏幕左侧glTranslatef - Left side of screen glTranslatef 如何将视图移动到屏幕的最近边缘? - How move a view to the nearest edge of the screen? 当我按下应用程序中的按钮时,所有editText和TextViews都会移至屏幕的左侧 - When I push a button in my app, all of the editText and TextViews move to the left side of the Screen 调用重绘后,Java Jpanels 按钮移动到屏幕的左上角。 我如何同时修复 Jpanel 使其保持正常? - Java Jpanels button move to the top left side of screen after repaint is called. How do I also repain Jpanel at the same time so it remains normal? 如何使用动画从右到左连续移动视图? - How to move a view from right to left continuous using animations? selenium webdriver 在左侧移动滑块 - selenium webdriver move slider on left side 如何使imageView在屏幕的一侧无限移动? [android动画] - How do I make imageView move infinitely from side to side of the screen? [android animation] 如何在左侧显示一个屏幕,而在右侧显示新窗口(同一屏幕中的多个视图) - how to display one screen in the left side while new window in the right (multiple views in the same screen) 如何将文字向左移动? - how to move the text to the left? JFreeChart:如何将 Y 轴从左侧移动到右侧? - JFreeChart: how to move Y-axis from left to right hand side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM