Android ActionBar 后退按钮和选项卡
我想创建一个 ActionBar
和一个选项卡式导航,如 google+ 应用程序。
我使用这个示例作为起点,现在我有一个很棒的操作栏:
我还添加了一个 ViewPager
和一个 TabHost
来显示选项卡并向左/右滚动片段。
我需要的是在蜂窝之前的版本中显示后退箭头。 如果我设置 getActionBar().setDisplayHomeAsUpEnabled(true)
,箭头会自动显示在 version >= honeycomb 中。
- 我怎样才能在蜂蜜之前的版本中做到这一点?
我还想要像 google+ 应用程序那样的选项卡。
这就是我的标签栏的外观:
删除了无效的 ImageShack 链接
...这就是我想要的:
删除了无效的 ImageShack 链接
我找不到任何样式示例像这样的标签栏。
I want to create an ActionBar
and a tabbed navigation like the google+ app.
I used this example as a starting point and now I have a great actionbar:
I've also included a ViewPager
and a TabHost
to have tabs and scrolling left/right Fragments.
What i need is to show the back arrow in version prior to honeycomb.
If I set getActionBar().setDisplayHomeAsUpEnabled(true)
, the arrow is automatically show in version >= honeycomb.
- How can I do that in version prior to honey?
What I also want to have is Tabs like the google+ app.
This is how is my tab bar looks:
removed dead ImageShack link
...and this is what i want:
removed dead ImageShack link
I can't find any example to style tab bars like that one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会推荐您使用 ActionBarSherlock 来实现 ActionBar 与 Android <3.0 的兼容性。这是比开发人员页面中提供的示例更好的实现。
使用此包,当您将以下行添加到活动中时,将出现后退箭头。
关于 Google+ 标签,我发现小部件 ViewFlow 非常有用,而且看起来完全一样。此外,您不存在任何向后兼容性问题。查看 CircleFlowIndicator 示例。
I would recommend you the ActionBarSherlock for ActionBar compatibility with Android <3. It is a better implementation that the example offered in the developers page.
Using this package, the back arrow will appear when you add to your activity the following line.
Regarding the Google+ tabs, I have found the widget ViewFlow very useful and looking exactly the same. Moreover, you don't have any backward compatibility issues. Have a look to the CircleFlowIndicator example.
您可以使用 ActionBarSherlock 和 ViewPager 与 ViewPagerIndicator 来实现想要的外观。这些库也在 ICS 之前工作。
正如 miguel.rodelas 建议的那样,使用 getSupportActionBar().setDisplayHomeAsUpEnabled(true) 作为主页箭头。在 onOptionsItemSelected 中,您可以通过 id android.R.id.home 捕获它。
You can use ActionBarSherlock and a ViewPager with ViewPagerIndicator to achieve the desired look. These libraries also work pre ICS.
As miguel.rodelas suggested, use getSupportActionBar().setDisplayHomeAsUpEnabled(true) for the home arrow. In onOptionsItemSelected you can catch it by the id android.R.id.home.
//在此处使用您的自定义 xml 视图
//您的点击监听器逻辑
//use your custom xml view here
//your logic for click listner
如前所述,在此处下载 ActionBarSherlock 并将其导入为库
https://api.github.com/repos/JakeWharton/ActionBarSherlock/zipball /4.2.0
然后只需复制您的代码,应该可以完美工作。
As stated, download the ActionBarSherlock and import it as a library here
https://api.github.com/repos/JakeWharton/ActionBarSherlock/zipball/4.2.0
Then just copy your code, should work perfectly.