Evenly spaced menu items on Toolbar

前端 未结 8 781
心在旅途
心在旅途 2020-12-01 02:09

So I\'ve been trying to implement android.support.v7.widget.Toolbar in my Activity and to make it look similar to the previously supported split ActionBar.

8条回答
  •  情话喂你
    2020-12-01 03:00

    The solution proposed by public void setupEvenlyDistributedToolbar(){} by kandroidj works perfectly. However to make the solution a bit more complete you need a custom OnclickListener:

    attached is my implementation

    private void setupOnClickListener4Toolbar(Toolbar toolbar) {
        Menu bottomMenu = toolbar.getMenu();
        for (int i = 0; i < bottomMenu.size(); i++) {
            bottomMenu.getItem(i).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    return onOptionsItemSelected(item);
                }
            });
        }
    }
    

提交回复
热议问题