How to control ActionBar split programmatically?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 18:43:29

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.

I don't believe so. I do not see anything in Activity that would serve as a setter counterpart to android:uiOptions.

The AppCompat package now offers the Toolbar widget that allows you to put an actionbar anywhere you want in your layout and modify it like any other view..

Please see the full documentation here and a guide here.

Atul O Holic

Can you try to set getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW) in the Activity you want the ActionBar to show as split right before its onCreate(), then hide it using getActionBar.hide() and on the list action you are referring to make it pop-up back using getActionBar.show().

I tried (not with the support libraries though) showing ActionBar in one Activity and Split in another using the above and was able to hide and show the split on button clicks. Hope this helps. Let me know in case it did or even didn't. Happy coding. :)

kotucz

You can use two Toolbars. Have a look at these questions:

AppCompat v7:21 Split Action Bar Broken?

How to center action menu on toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!