-1

I looking for TabLayout with following custom behaviour

  • Custom font
  • Text color change on select & un select of Tab
  • Bold & normal font on select & un select of Tab
  • By default 1st tab should be selected with Bold text

I am attaching following code snippet which all I tried for it.

1) I've created custom view Called FundayTabLayout

<com.knackv.custom.view.FundayTabLayout
    android:id="@id/dashboard_tab_layout"
    style="@style/AppTabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabTextAppearance="@style/AppTabTextAppearance"></com.knackv.custom.view.FundayTabLayout>

2) Styles which I've used

<style name="AppTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabMaxWidth">@dimen/size_in_150_dp</item>
    <item name="tabIndicatorColor">@color/app_background</item>
    <item name="tabBackground">@drawable/tab_background_color_selector</item>
    <item name="tabTextAppearance">@style/AppTabTextAppearance</item>
    <item name="tabSelectedTextColor">@color/app_blue</item>
</style>

<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">@dimen/size_in_15_dp</item>
    <item name="textAllCaps">false</item>
</style>

3) setting up my custom font:

 @Override
public void setupWithViewPager(@Nullable ViewPager viewPager) {
    super.setupWithViewPager(viewPager);

    this.removeAllTabs();

    ViewGroup slidingTabStrip = (ViewGroup) getChildAt(0);
    for (int i = 0, count = viewPager.getAdapter().getCount(); i < count; i++) {
        Tab tab = this.newTab();
        this.addTab(tab.setText(viewPager.getAdapter().getPageTitle(i)));
        AppCompatTextView view = (AppCompatTextView) ((ViewGroup) slidingTabStrip.getChildAt(i)).getChildAt(1);
        view.setAllCaps(false);
        view.setTypeface(Utility.getNormalTypeFace());
    }
}

Please provide me optimum solution for this issue.

Shanmugapriyan
  • 953
  • 1
  • 10
  • 28

2 Answers2

0
Typeface fontTypeFace = Typeface.createFromAsset(getAssets(), "OpenSans-Semibold.ttf");

    for (int i = 0; i < tabLayout.getChildCount(); ++i) {
        View nextChild = tabLayout.getChildAt(i);
        if (nextChild instanceof TextView) {
            TextView textViewToConvert = (TextView) nextChild;
            textViewToConvert.setTypeface(fontTypeFace);
        }
    }

try this

0

https://stackoverflow.com/a/31067431/5726971 check this.. it's mainly for android design support TabLayout. https://stackoverflow.com/a/33284990/5726971 this one added to the first answer in case of using custom TabLayout like your case.

Community
  • 1
  • 1