尝试使用 PagerSlidingTabStrip 制作可滑动的标签,但标签标题不会出现,只有布局内容会出现

Tried of making swipeable tab using PagerSlidingTabStrip but tab title is not coming only the content of layout is coming

您好,我尝试制作可滑动的选项卡布局。布局即将到来并且可以滑动,但选项卡的标题没有到来。在我的 MainActivity 代码中是:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity_layout);

    // Initialization
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new TabsPagerAdapter(getSupportFragmentManager()));

    PagerSlidingTabStrip tabsStrip = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    tabsStrip.setViewPager(viewPager);

    tabsStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            Toast.makeText(EditActivity.this, "Selected page position: " + position, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}

我的 TabsPagerAdapter 代码如下:

public class TabsPagerAdapter extends FragmentPagerAdapter {

    // Tab titles
    private String[] tabs = new String[] {"Profile", "Child"};

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

    @Override
    public Fragment getItem(int position) {

        switch (position) {
            case 0:
                // User fragment activity
                return new UserFragment();
            case 1:
                // Child fragment activity
                return new ChildFragment();
        }
        return null;
    }

    @Override
    public int getCount() {
        return tabs.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // Generate title based on item position
        return tabs[position];
    }
}

我的 mainactivity_layout.xml 是:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_no_padding"
android:paddingLeft="@dimen/activity_no_padding"
android:paddingRight="@dimen/activity_no_padding"
android:paddingTop="@dimen/activity_no_padding"
tools:context="com.samvardhan.org.vaccinationinfo.EditActivity">

<com.astuetz.PagerSlidingTabStrip
    android:id="@+id/tabs"
    app:pstsShouldExpand="true"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:textSize="14sp"
    android:textColor="#000000"
    app:pstsDividerColor="@color/green"
    app:pstsIndicatorColor="@color/red"
    app:pstsUnderlineColor="@color/blue"
    app:pstsTabPaddingLeftRight="14dp"/>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v4.view.ViewPager>

</RelativeLayout>

我的两个选项卡有两个布局 xml 文件。两个选项卡的内容即将到来,但不是选项卡的标题。

标签只有内容,没有标题。我缺少什么?

添加一个

android:layout_below="@+id/tabs"

xml 中的 ViewPager

您是否尝试过更改 com.astuetz.PagerSlidingTabStrip 的文本颜色 (android:textColor="#000000") 到你的 mainactivity_layout.xml

中的另一个值