android中修改tablayout中的字体大小和颜色

       按步骤来吧。

         一、activity_main.xml:

<android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextAppearance="@style/MyTabLayoutTextAppearance" />

        二、values/styles.xml:

<style name="MyTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">@android:color/white</item>
    </style>
    <style name="MyTabLayoutTextAppearanceInverse" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse">
        <item name="android:textSize">15sp</item>
        <item name="android:textColor">@android:color/holo_red_light</item>
    </style>

        三、MainActivity.java:

TabLayout tabLayout=(TabLayout)findViewById(R.id.tablayout);
        ViewPager viewPager=(ViewPager)findViewById(R.id.viewpager);
        if(viewPager!=null)
        {
            Fragment1 fragment1=new Fragment1();
            Fragment2 fragment2=new Fragment2();
            FragmentAdapter adapter=new FragmentAdapter(getSupportFragmentManager());
            adapter.addFragment(fragment1,"字体");
            adapter.addFragment(fragment2,"颜色");
            viewPager.setAdapter(adapter);
            tabLayout.setupWithViewPager(viewPager);
        }


你可能感兴趣的:(android中修改tablayout中的字体大小和颜色)