tsengvn / typekit

148 stars 27 forks source link

SlidingTabLayout title not changing #5

Closed necipallef closed 8 years ago

necipallef commented 8 years ago

I am using SlidingTabLayout* and each page's title remains the same, while other views in the layout changes according to TypeKit settings.

*for SlidingTabLayout, please refer to link: http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html

ParkSangGwon commented 8 years ago

You have to setCustomView in your TabLayout. In my case, I use TabLayout ( android.support.design.widget ). I had same problem like you.

I made LayoutUtils for apply CustomFontTab. This is my code. You can apply this code to your SlidingTabLayout

public class LayoutUtil {

    public static void applyFontedTab(Activity activity, ViewPager viewPager, TabLayout tabLayout ) {
        for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
            TextView tv = (TextView) activity.getLayoutInflater().inflate(R.layout.view_item_tablayout, null);

            if (i == viewPager.getCurrentItem()) tv.setSelected(true);

            tv.setText(viewPager.getAdapter().getPageTitle(i));
            tabLayout.getTabAt(i).setCustomView(tv);
        }

    }

}
necipallef commented 8 years ago

I was using FragmentPagerAdapter and FragmentManager for tabs in the ViewPager, you are suggesting to switch to using TabLayout? I'd be happier if I didn't have to change the structure, cause I am not sure what is the difference between two.

ParkSangGwon commented 8 years ago

I saw setCustomTabView() in SlidingTabLayout class. you can use setCustomTabView() instead of my code

necipallef commented 8 years ago

Using setCustomTabView() and removing tabTitleView.setTypeface(null, Typeface.BOLD); line inside SlidingTabLayout$populateStrip() method worked. Thank you.