谷歌刚刚为其Google Play选项卡实施了一个新外观。
我知道可以使用ViewPagerIndicator来实现,但我不想在我的应用程序中使用另一个库并使应用程序的大小增加大约1MB左右。
我目前正在使用android.support.v4.view.PagerTabStrip(就像在旧版Google Play中一样),我想知道是否也可以使用android support库来实现新的外观。
提前感谢。
谷歌刚刚为其Google Play选项卡实施了一个新外观。
我知道可以使用ViewPagerIndicator来实现,但我不想在我的应用程序中使用另一个库并使应用程序的大小增加大约1MB左右。
我目前正在使用android.support.v4.view.PagerTabStrip(就像在旧版Google Play中一样),我想知道是否也可以使用android support库来实现新的外观。
提前感谢。
设计支持库包括 TabLayout
组件,可帮助您实现类似 Google Play 的选项卡:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
然后进行初始化:
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
完整的示例请参见 Cheesesquare 应用程序
这是一个可直接使用的库,您可以在 Github 上找到它。
Google终于发布了他们的滑动标签API。
要使用SlidingTabsBasic,您首先需要从以下网址下载zip文件: http://developer.android.com/downloads/samples/SlidingTabsBasic.zip
来自Google的示例布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.android.common.view.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
在您的Activity的onCreate()方法中示例代码:
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setViewPager(mViewPager);
更多详细信息,请参考zip文件中的示例,其中包括SlidingTabsBasicFragment.java和fragment_sample.xml