How to control ActionBar split programmatically?

后端 未结 5 678
陌清茗
陌清茗 2020-12-13 19:34

The android ActionBar may split into a top and bottom bars if activity\'s parameter \"uiOptions\" is set to \"splitActionBarWhenNarrow

5条回答
  •  隐瞒了意图╮
    2020-12-13 20:33

    No, you cannot switch between split and non-split action bars on the fly.

    The setter counterpart to android:uiOptions is on Window, not Activity. Window#setUiOptions is the method and the flag to use is ActivityInfo#UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW.

    However this isn't going to do what you want. Split action bar when narrow must be specified as the window is first configured before the window decor is initialized. In other words, once the window has been displayed (or even once you've called setContentView) it's too late to change it.

    This was a conscious decision by the Android UX team. Action modes (including selection modes) are meant to mirror the configuration of the action bar on the current activity. This gives the user a single place to look for currently valid actions within the same activity.

提交回复
热议问题