tablayout现在显示api +21中的选项卡

时间:2018-06-11 11:23:23

标签: android android-tablayout android-tablelayout android-design-library

这是我在我的应用程序中制作标签的代码:

<android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


            <include
                android:id="@+id/appbar"
                layout="@layout/appbar" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="fixed"
                app:tabGravity="fill"
                app:tabIndicatorColor="#F48917"
                app:tabIndicatorHeight="2.5dp"
                app:tabTextColor="#fff">

            </android.support.design.widget.TabLayout>
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这是布局代码。

这是我制作标签的java代码:

viewPager = (ViewPager) findViewById(R.id.viewpager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

    tabLayout.post(new Runnable() {
        @Override
        public void run() {
            setupViewPager(viewPager);
        }
    });
private void setupViewPager(ViewPager viewPager) {
    FistActiivty home=new FistActiivty();
    SupportOnline contact=new SupportOnline();

    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(contact, "پشتیبانی آنلاین");
    adapter.addFragment(home, "خانه");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

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

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}

它可以找到它,它显示了android 4及以下的标签,但它没有在android api +21上显示它们(像android 6)

这是我的傻瓜:

 compileSdkVersion 26
buildToolsVersion '27.0.3'
    compile 'com.android.support:design:26.0.0-alpha1'

这是什么问题?我该怎么解决?

0 个答案:

没有答案