因此,效果将是每个单独的选项卡会稍微变大,并且文本颜色也会改变。我尝试使用setCustomTabView()方法,但它只适用于第一个选项卡,其余选项卡未呈现。
因此,效果将是每个单独的选项卡会稍微变大,并且文本颜色也会改变。我尝试使用setCustomTabView()方法,但它只适用于第一个选项卡,其余选项卡未呈现。
下面是一个使用setCustomTabView()的示例:
在您的布局中,您有ViewPager和SlidingTabLayout:
<com.yourProject.SlidingTabLayout <--- IMPORT latest from Google[*see link]
android:id="@+id/sliding_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager android:id="@+id/viewPager"
android:layout_marginTop="@dimen/text_size_medium"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
然后在你的 Fragment 或 Activity 中,像这样设置滑动选项卡的自定义视图:
viewPager = (ViewPager) rootView.findViewById(R.id.viewPager);
mSlidingTabLayout = (SlidingTabLayout) rootView.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
mSlidingTabLayout.setCustomTabView(R.layout.sliding_tab_layout_custom, R.id.item);
mSlidingTabLayout.setDistributeEvenly(false);
mSlidingTabLayout.setViewPager(viewPager);
使用自定义选项卡布局:
../layout/sliding_tab_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/text_size_small"
android:textColor="@color/primary"
android:textSize="@dimen/text_size_medium"/>
</LinearLayout>