在某些版本的 Android 上有选择地启用操作栏
我目前正在将一个应用程序移植到平板电脑上。在这个过渡时期,我希望应用程序安装在平板电脑上时看起来非常像蜂窝状。特别是,我希望应用程序安装在平板电脑上时具有操作栏。但是,当应用程序安装在手机上时,我不想要操作栏,因为此时我不想重新设计手机体验以适应操作栏。
让我的应用程序在手机上安装时看起来与当前相同,但在平板电脑上安装时添加操作栏的最佳方法是什么?
I have an application that I'm currently porting to tablets. During this transitional period I would like to have the app look very honeycomb-like when installed on tablets. In particular, I would like the the app to have an Action bar when installed on tablets. However, I do NOT want an action bar when the app is installed on phones, since I do not want to redesign the phone experience to accommodate an action bar at this time.
What is the best way to have my app look the same as it currently does when installed on phones, but add an action bar when it's installed on tablets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在手机和平板电脑上使用不同的风格来实现我想要的目标。
在 res/values/styles.xml 中,我将默认(手机)样式配置为从 Theme.Light 继承
在 res/values-xlarge-mdpi/styles.xml 中,我使用 Theme.Holo,因为 ActionBar 文档指定所有 Theme.Holo 活动都有操作栏。
当然,我的 AndroidManifest 指定了要使用的主题:
这似乎在平板电脑设备上给了我一个操作栏,但在手机设备上没有操作栏。
I managed to accomplish what I wanted by using a different style for phones and for tablets.
In res/values/styles.xml I have my default (phone) style configured to inherit from Theme.Light
In res/values-xlarge-mdpi/styles.xml I use Theme.Holo, because the ActionBar docs specify that all Theme.Holo activities have the action bar.
And of course I have my AndroidManifest specifies the theme to use:
This seems to give me an action bar on tablet devices but no action bar on phone devices.
为您的平板电脑设备使用单独的布局文件。将 large 或 xlarge 附加到目录末尾将仅允许这些设备访问它。
例如:
Use a separate layout file for your tablet devices. Append large or xlarge to the end of the directory will allow only those devices access to it.
For example: