1

I'm trying to implement design, that my designer had made for me.

I can't move compoundDrawable closer to text (setting padding attribute can move it far away, but even 0dp doesn't make it close) and I can't make constant width with spacing between tabs.

Tabs design

Here's what I get (don't look at fonts, text colors, underscore size, currently in development):

enter image description here

But I've met troubles with customizing Jake's Wharton library

Here is almost same question: Space between elements of the indicator

<style name="SkillsPageIndicator" parent="Widget.TabPageIndicator">
        <item name="android:background">@drawable/tab_underline_indicator</item>
        <item name="android:textSize">@dimen/text_size_medium</item>
        <item name="android:paddingTop">35dp</item>
        <item name="android:paddingBottom">16dp</item>
        <item name="android:drawablePadding">0dp</item>
        <item name="android:gravity">center</item>
        <item name="android:width">100dp</item>
</style>
Community
  • 1
  • 1
Anton Shkurenko
  • 4,301
  • 5
  • 29
  • 64

1 Answers1

1

I've made not so clean code, but it works for me. I share it here to help anyone, who will need it:

done image

Change code in the TabPageIndicator.addTab:

private void addTab(int index, CharSequence text, int iconResId) {
        final TabView tabView = new TabView(getContext());
        tabView.mIndex = index;
        tabView.setFocusable(true);
        tabView.setOnClickListener(mTabClickListener);
        tabView.setText(text);

        /**
         *  My parts (CullyCross):
         */

        Resources r = getResources();
        DisplayMetrics metrics = r.getDisplayMetrics();
        float screenWidth  = metrics.widthPixels;

        float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, metrics);
        int margin = (int)(screenWidth - 2 * width) / 4;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int)width, MATCH_PARENT);
        params.setMargins(margin, 0, margin, 0);


        /***********************/

        if (iconResId != 0) {
            tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        }

        /**
         * original
         * mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
         */

        mTabLayout.addView(tabView, params);
    }

With thiner font it would look nicer.

Anton Shkurenko
  • 4,301
  • 5
  • 29
  • 64