使 ActionBar 上的选项卡在达到限制时滚动,而不是创建下拉列表
正如标题所示,我有一个 Android 4.0 平板电脑应用程序,它使用操作栏和选项卡模式。
如果我向操作栏添加超过 4 或 5 个选项卡,则会创建一个下拉列表。我已阅读文档,其中指出:“注意:在某些情况下,Android 系统会将操作栏选项卡显示为下拉列表,以确保最适合操作栏。”
只是想知道是否可以覆盖默认行为并让操作栏滚动项目?设计文档 http://developer.android.com/design/patterns/actionbar.html< /a> 谈论可滚动选项卡,但除了设计文档之外,我似乎找不到有关它们的任何信息。
As the title suggests, I have an Android 4.0 Tablet app, that uses the Actionbar and tab mode.
If I add any more than 4 or 5 tabs to the action bar, a dropdown list is created instead. I have read the documentation, which states, "Note: In some cases, the Android system will show your action bar tabs as a drop-down list in order to ensure the best fit in the action bar."
Was just wondering if it is possible to override the default behavior and get the actionbar to scroll the items? The design document http://developer.android.com/design/patterns/actionbar.html talks about scrollable tabs, but I can't seem to find any information on them other than in the design document.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我一直在努力让它发挥作用。然而,在使用 ActionBarSherlock 之后,解决方案非常简单。如果您下载示例 Styled 源并查看 MainActivity 类,您可以看到它创建并添加选项卡,并在其下方:
我在添加选项卡之前调用了这些选项卡,并且我的选项卡已变成下拉列表。事实证明,您所需要做的就是在添加选项卡后调用它们,而不是保留滚动选项卡。
I have been struggling to get this to work. However, after playing with ActionBarSherlock, the solution is infuriatingly easy. If you download the sample Styled source and look in the MainActivity class, you can see it create and add the tabs, and beneath that:
I had called these BEFORE adding the tabs, and my tabs had been turned into a drop-down list. Turns out, all you need to do is call them after adding the tabs instead to keep the scrolling tabs.
请阅读 http://developer.android 中的“添加操作视图”部分。 com/guide/topics/ui/actionbar.html
的引用,将
HorizontalScrollView
用作操作视图您可以通过在
public boolean onCreateOptionsMenu(Menu menu)
中指定获取对此HorizontalScrollView
定义一个
RadioGroup< /code> 与一些
RadioButton
,其中每个RadioButton
当被选中时,将更新其关联的选项卡内容。现在将此RadioGroup
添加到HorizontalScrollView
中,您将在public boolean onCreateOptionsMenu(Menu menu)
中获得它,您可以使用
selectTab(ActionBar.Tab tab)
或其他等效方法来更新选项卡内容。您可以通过将
android:button
设置为透明图像,然后设置一些状态为选中、选中和正常的StateListDrawable
来更改 RadioButton 的外观。请参阅我使用此方法得到的下面的屏幕。
在上图中,每个
RadioButton
选中时会选择不同的选项卡。Read the "Adding an Action View" section from http://developer.android.com/guide/topics/ui/actionbar.html
You can use
HorizontalScrollView
as action view by specifyingGet reference to this
HorizontalScrollView
inpublic boolean onCreateOptionsMenu(Menu menu)
Define a
RadioGroup
with someRadioButton
where eachRadioButton
when selected, will update its associated tabs contents. Now add thisRadioGroup
toHorizontalScrollView
which you will get inpublic boolean onCreateOptionsMenu(Menu menu)
You can use
selectTab(ActionBar.Tab tab)
or some other equivalent method to update tabs contents.You can change the look of
RadioButton
by settingandroid:button
to transparent image and then setting someStateListDrawable
with states checked, selected and normal..See below screen I got using this method.
In above image, each
RadioButton
when checked, selects different tab.您是否检查过 SDK 中的 Honeycomb Gallery 示例应用程序?它可能有您正在寻找的东西。将其安装在 ICS 非平板电脑设备上以查看可滚动选项卡。平板电脑的屏幕空间太大,无法滚动。
http://developer.android.com/resources/samples/HoneycombGallery/index.html
Have you checked out the Honeycomb Gallery sample app in the SDK? It might have what you are looking for. Install it on an ICS non-tablet device to see the scrollable tabs. A tablet has too much screen space for it to scroll.
http://developer.android.com/resources/samples/HoneycombGallery/index.html
UI 如此工作是有原因的。拥有一组可滚动的选项卡是非常令人困惑的。很可能根本不清楚右侧有更多可用选项卡,并且用户永远不会知道他们可以滚动选项卡以获得更多功能。
我建议坚持平台的设计工作方式。它做事通常都是有原因的。
The UI works the way it is for a reason. It is extremely confusing to have a scrollable set of tabs. There is a good chance that it won't be clear at all that there are more tabs available on the right, and the user will never know they can scroll the tabs to get to more features.
I recommend sticking with how the platform is designed to work. It generally does things for a reason.