判断ActionBar是否堆叠

发布于 2024-12-29 11:29:39 字数 361 浏览 1 评论 0原文

如果您向 ActionBar 添加选项卡,它们将位于纵向模式手机上额外堆叠的 ActionBar 中。有没有一种简单的方法可以查明是否发生了这种情况?

我附上了 YouTube 应用的两张屏幕截图。第一个显示了其中包含选项卡的普通 ActionBar,第二个显示了堆叠 ActionBar 中的选项卡。

Youtube 应用程序(横向) Youtube 应用程序(肖像)

If you add tabs to your ActionBar, they will be in an extra stacked ActionBar on phones in portrait mode. Is there an easy way to find out whether this happened?

I've attached two screenshots of the YouTube app. The first one shows the normal ActionBar with the tabs in it, the second one shows the tabs in a stacked ActionBar.

Youtube App (landscape)
Youtube App (portrait)

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

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

发布评论

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

评论(3

寂寞陪衬 2025-01-05 11:29:39

通过高度可以判断操作栏中是否有一行或两行。有方法 getHeight() ,但它不会在 onCreateonStart 中工作,只有当 Activity 已经启动时它才会返回实际值。

在横向方向上,操作栏的高度为 40dip(在不同屏幕上为 80/60/40/30 像素),在带有选项卡的纵向方向上,高度为 96dp(192/144/96/72 像素)。

依赖于此并不是最好的主意,但我找不到任何其他方法来确定选项卡是否位于操作栏中。

It is possible to find out if there is one or two lines in action bar by is's height. There is method getHeight(), but it will not work in onCreate or onStart, it will return real value only if activity already started.

In landscape orientation height of action bar is 40dip (80/60/40/30 px on different screens), in portrait orientation with tabs it is 96dp (192/144/96/72 px).

It is not the best idea to rely on this, but I can't find any other way to find out if tabs is inside action bar.

哀由 2025-01-05 11:29:39

此行为称为拆分操作栏。当在 中使用 uiOptions="splitActionBarWhenNarrow" 设置 AndroidManifest 时,会发生这种情况代码> 元素。

Android 根据当前屏幕尺寸以多种方式调整操作栏的外观。使用拆分操作栏只是您可以启用的一种选项,可以让操作栏进一步优化不同屏幕尺寸的用户体验。这样做时,您还可以允许操作栏将导航选项卡折叠到主操作栏中。也就是说,如果您在操作栏中使用导航选项卡,一旦操作项在狭窄的屏幕上分开,导航选项卡可能能够适合主操作栏,而不是分成“堆叠操作栏”。

>可以在此处获取更多详细信息。

This behavior is called Split Action Bar. It happens when the AndroidManifest is set with uiOptions="splitActionBarWhenNarrow" in the <activity> or <application> element.

Android adjusts the action bar's appearance in a variety of ways, based on the current screen size. Using split action bar is just one option that you can enable to allow the action bar to further optimize the user experience for different screen sizes. In doing so, you may also allow the action bar to collapse navigation tabs into the main action bar. That is, if you use navigation tabs in your action bar, once the action items are separated on a narrow screen, the navigation tabs may be able to fit into the main action bar rather than be separated into the "stacked action bar".

Mock-ups of split action bar with navigation tabs on the left; with the app icon and title disabled on the right.

You can get more details here.

有木有妳兜一样 2025-01-05 11:29:39

好吧,我创建了一个类似于 Instagram 的 actionBar,带有底部 ActionBar,而不需要使用选项卡。看看这张图片。我十分钟前在另一个问题上回答了这个相关问题。
自定义视图操作栏和假底部操作栏
为了做到这一点,您必须创建三个单独的布局。一个用于底部,将其用作 Include,另一个用于 ActionBar,将其用作 ActionBar 视图。

如果您查看我的最新答案,您会发现我是如何做到这一点的。
无论如何希望这对你有好处。干杯

well i have created an actionBar similar to Instagram with a bottom ActionBar without the need of using Tabs. have a look at this image . i'v answered this related question on another question 10 minutes ago.
CustomView ActionBar And Fake Bottom ActionBar
in order for you to do this you have to create three separate layouts. one for the bottom to use it as Include and one for the ActionBar To use it As ActionBar View.

if you check my latest answers you'll find how i did this.
hope that benefits you in anyway. cheers

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