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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wode_dream/article/details/50424446

       按步骤来吧。

         一、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);
        }


猜你喜欢

转载自blog.csdn.net/wode_dream/article/details/50424446