6

I'm developing an android app and recently we decided to mix up the design and switch our main screen to a view pager with tabs on top (actually in the actionbar). To place the tabs on top I was thinking of using a custom actionbar layout and for the tabs to use the PagerSlidingTabStrip library but I also need that instead of text to have an icon that changes colour as you swipe (if the page is selected or not), as it is used on the Facebook app or Tinder 1

Does anyone have any suggestion for this? I saw that there was a branch made on the tab library that should have done exactly this, but I couldn't get it to work.

4

1 回答 1

6

好的,找到了如何将图像添加到选项卡中,不得不通过 PagerSlidingTab 库的代码。

PagerSlidingTab 包含一个名为 IconTabProvider 的接口,需要由 ViewPager 的适配器实现。实现了这一点,您可以为每个位置提供不同的图标。

我现在唯一的问题是,我需要根据是否选择了选项卡来使用不同颜色的图标,并且两者之间的过渡缓慢(就像在 Tinder 和 Facebook 上一样)。

LE:显然很幸运,这里有一个标签条库的分支。您只需要像这样创建的可绘制资源:

<item android:state_selected="true" android:drawable="@drawable/ic_twitter"/>
<item android:drawable="@drawable/ic_twitter_of"/>

每当您选择一个新页面时,它都会发生变化,但在打开和关闭图标之间没有平滑过渡。

乐 2:

找到另一个具有平滑选项卡转换的分支(使用 alpha 属性显示一个很好的转换),可以在这里找到。唯一的问题是它不支持状态切换图标,所以我决定将两个分叉结合起来。感谢两位创作者的出色工作,为我节省了大量时间:)。

于 2015-01-14T16:04:59.427 回答