0

我想将活动选项卡的文本颜色更改为白色。现在我正在使用选择器,非活动选项卡是灰色的,但活动选项卡不是白色的。

XML 选择器:

    <!-- Tab is active  -->
    <item   android:state_checked="true" 
            android:color="@color/tab_color_active" /> 

    <!-- Default -->
    <item   android:color="@color/tab_color_default"  /> 

</selector>

布局部分:

<android.support.v4.view.PagerTabStrip
    android:id="@+id/pager_tab_strip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="#3D3D3D"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    android:textColor="@drawable/tab_selector" />

这是我的片段的相关代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_community, container, false);

    viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
    viewPager = (ViewPager) rootView.findViewById(R.id.pager);
    viewPager.setAdapter(viewPagerAdapter);

    pagerTabStrip = (PagerTabStrip) rootView.findViewById(R.id.pager_tab_strip);
    pagerTabStrip.setDrawFullUnderline(true);
    pagerTabStrip.setTabIndicatorColor(Color.WHITE);


    return rootView;
}

ViewPagerAdapter:

public class ViewPagerAdapter extends FragmentPagerAdapter {
    final int PAGE_COUNT = 4;
    private String tabTitles[] = new String[] {"Tab 1", "Tab 2", "Tab 3", "Tab 4"};

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch(position) {
        case 0:
            Fragment1 fragment1 = new Fragment1();
            return fragment1;
        case 1:
            Fragment2 fragment2 = new Fragment2();
            return fragment2;
        case 2:
            Fragment3 fragment3 = new Fragment3();
            return fragment3;
        case 3:
            MyImagesFragment fragment4 = new MyImagesFragment();
            return fragment4;
        }

        return null;
    }

    @Override
    public int getCount() {
        return PAGE_COUNT;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        Locale l = Locale.getDefault();

        return tabTitles[position].toUpperCase(l);
    }
}

这是它的样子: http: //fs1.directupload.net/images/150409/3msfxnnl.png

我希望 Tab 1 的文本颜色为白色,因为它处于活动状态。此外,我希望开始选项卡是 Tab 2 而不是 Tab 1。有谁知道该怎么做?

4

0 回答 0