判断ActionBar是否堆叠
如果您向 ActionBar
添加选项卡,它们将位于纵向模式手机上额外堆叠的 ActionBar
中。有没有一种简单的方法可以查明是否发生了这种情况?
我附上了 YouTube 应用的两张屏幕截图。第一个显示了其中包含选项卡的普通 ActionBar
,第二个显示了堆叠 ActionBar
中的选项卡。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过高度可以判断操作栏中是否有一行或两行。有方法
getHeight()
,但它不会在onCreate
或onStart
中工作,只有当 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 inonCreate
oronStart
, 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.
此行为称为拆分操作栏。当在
或
中使用uiOptions="splitActionBarWhenNarrow"
设置AndroidManifest
时,会发生这种情况代码> 元素。Android 根据当前屏幕尺寸以多种方式调整操作栏的外观。使用拆分操作栏只是您可以启用的一种选项,可以让操作栏进一步优化不同屏幕尺寸的用户体验。这样做时,您还可以允许操作栏将导航选项卡折叠到主操作栏中。也就是说,如果您在操作栏中使用导航选项卡,一旦操作项在狭窄的屏幕上分开,导航选项卡可能能够适合主操作栏,而不是分成“堆叠操作栏”。
>可以在此处获取更多详细信息。
This behavior is called Split Action Bar. It happens when the
AndroidManifest
is set withuiOptions="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".
You can get more details here.
好吧,我创建了一个类似于 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.

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