How to align items in action bar to the left?

后端 未结 2 1341
梦毁少年i
梦毁少年i 2020-12-09 22:41

I have an actionbar with a searchview but I\'d like to align it to the left such as in the maps app as opposed to the right. How would I do this?

2条回答
  •  情书的邮戳
    2020-12-09 23:14

    You can do this Try this it would definetly help:

    ActionBar action=getActionBar();
    action.setDisplayShowCustomEnabled(true);
    action.setDisplayShowHomeEnabled(false);
    action.setDisplayShowTitleEnabled(false);
    RelativeLayout relative=new RelativeLayout(getApplicationContext());
    relative.addView(new SearchView(getApplicationContext()));
    action.setCustomView(relative);
    

    Do not forget to add layout params to your searchview so that it may align on right to relative. Do let me know if any issue got. Thank You

    it would be then shown on right of action bar. Also

提交回复
热议问题