Android support toolbar: resizing will not redistribute menu items

I am trying to resize the Android support toolbar Activitywhen changing orientation since it is too large in landscape mode. It does not change automatically when used

android:configChanges="orientation|screenSize"

in my activity, and therefore the activity will not be recreated. The XML toolbar is as follows:

<android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

in my onConfigurationChanged()I resize the toolbar for example. eg:

findViewById(R.id.my_awesome_toolbar).setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 114));

The result is not as expected. Menu items that are filled with setSupportActionBar(toolbar);and onCreateOptionsMenu()are incorrectly aligned vertically, and not a single navigation icon ( toolbar.setNavigationIcon(...):

7O153Nm.png

- , ?

+4
1

setMinimumHeight , .

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Toolbar tb = getActionBarToolbar();
    if (tb != null) {
        int size = UIUtils.calculateActionBarSize(this);
        tb.setMinimumHeight(size);
        ViewGroup.LayoutParams lp = tb.getLayoutParams();
        lp.height = size;
        tb.setLayoutParams(lp);
    }
}
+2

All Articles