How to align items in action bar to the left?

后端 未结 2 1335
梦毁少年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:01

    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);
    

提交回复
热议问题