开发者

How to align items in action bar to the left?

开发者 https://www.devze.com 2023-04-05 17:57 出处:网络
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 开发者_StackOverflow社区would I do this?You can do this

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 开发者_StackOverflow社区would I do this?


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


Don't work with getApplicationContext() , i found an issue

    RelativeLayout relative = new RelativeLayout(mActionBar.getThemedContext());
    mSearchView = new SearchView(mActionBar.getThemedContext());
    mSearchView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setGravity(Gravity.LEFT);
    relative.addView(mSearchView);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setCustomView(relative);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号