如何以编程方式控制ActionBar分割?

发布于 2024-12-18 05:09:12 字数 355 浏览 1 评论 0原文

如果 Activity 的参数“uiOptions”设置为“splitActionBarWhenNarrow”,则 android ActionBar 可能会拆分为顶部和底部栏,请注意此参数仅适用于在 ICS 中有效。

Honeycomb 引入了一种使用操作栏多选列表项的新方法。当一个项目被按下时,按住列表会变成多选模式,并且可以使用操作栏来完成一些操作。操作栏设置继承自列表活动,即,如果活动具有拆分操作栏,则多选也将具有,如果活动仅具有顶部栏,则多选将与之兼容。

问题是,是否可以在活动中只有一个顶部操作栏,并且当列表变成多选模式时以编程方式拆分操作栏?

谢谢!

The android ActionBar may split into a top and bottom bars if activity's parameter "uiOptions" is set to "splitActionBarWhenNarrow", note this parameter is only valid in ICS.

Honeycomb has introduced a new approach to multi-select list items using action bar. When a item is under press & hold the list becomes into a multi-selection mode and the actionbar bar may be used to accomplish some actions. The actionbar setup is inherited from the list activity, i.e., if the activity has a split action bar the multi-selection will have too, and if the activity has only the top bar, so, the multi-selection will be compliant with that.

The question is, is it possible to have only a top action bar in the activity and when the list turns into multi-selection mode programmatically split the actionbar?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暗地喜欢 2024-12-25 05:09:12

不可以,您无法在分割和非分割操作栏之间即时切换。

android:uiOptions 的 setter 对应项位于 Window 上,而不是 Activity 上。 Window#setUiOptions 是方法,要使用的标志是 ActivityInfo#UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW

然而,这不会做你想做的事。必须指定狭窄时的拆分操作栏,因为窗口是在初始化窗口装饰之前首先配置的。换句话说,一旦窗口显示(或者甚至调用setContentView),再更改它就为时已晚。

这是 Android UX 团队有意识的决定。操作模式(包括选择模式)旨在反映当前活动上操作栏的配置。这为用户提供了一个在同一活动中查找当前有效操作的位置。

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.

殊姿 2024-12-25 05:09:12

我不相信是这样。我在 Activity 中没有看到任何可以作为 android:uiOptions 的 setter 对应项的内容。

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

池予 2024-12-25 05:09:12

AppCompat 包现在提供了工具栏小部件,允许您将操作栏放置在布局中的任何位置,并像任何其他视图一样修改它。

请参阅完整文档 此处 和指南 此处

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.

故人的歌 2024-12-25 05:09:12

您是否可以尝试在 Activity 中设置 getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW) 您希望 ActionBar 在其之前显示为拆分onCreate(),然后使用 getActionBar.hide() 隐藏它,并在您引用的列表操作上创建它使用getActionBar.show()弹出回来。

我尝试(尽管不是使用支持库)在一个 Activity 中显示 ActionBar 并使用上述方法在另一个 Activity 中拆分,并且能够隐藏和显示按钮单击时的拆分。希望这有帮助。如果有或没有,请告诉我。快乐编码。 :)

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. :)

撩动你心 2024-12-25 05:09:12

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文