如何以编程方式控制ActionBar分割?
如果 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不可以,您无法在分割和非分割操作栏之间即时切换。
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 onWindow
, notActivity
.Window#setUiOptions
is the method and the flag to use isActivityInfo#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.
我不相信是这样。我在
Activity
中没有看到任何可以作为android:uiOptions
的 setter 对应项的内容。I don't believe so. I do not see anything in
Activity
that would serve as a setter counterpart toandroid:uiOptions
.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.
您是否可以尝试在
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 theActivity
you want theActionBar
to show as split right before itsonCreate()
, then hide it usinggetActionBar.hide()
and on the list action you are referring to make it pop-up back usinggetActionBar.show()
.I tried (not with the support libraries though) showing
ActionBar
in oneActivity
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. :)您可以使用两个工具栏。看看这些问题:
AppCompat v7:21 拆分操作栏损坏?
如何使操作菜单在工具栏上居中
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