Modify the width of TabLayout slide wires

If the font width is the same as the one you set, you can write the Reflex directly and call this method where the TabLayout is initialized

 mReflex = new Reflex();
 mReflex.reflex(mTabLayout);
Copy the code
Public class Reflex {public void Reflex (final TabLayout TabLayout){public void Reflex (final TabLayout TabLayout){tabLayout.post(new) Runnable() {@override public void run() {try {LinearLayout mTabStrip = (LinearLayout) tabLayout.getChildAt(0); int dp10 = dip2px(tabLayout.getContext(), 10); for (int i = 0; i < mTabStrip.getChildCount(); i++) { View tabView = mTabStrip.getChildAt(i); MTextView Field = mTextViewField = mTextViewField = mTextViewField = mTextViewField = mTextViewField = mTextViewField = mTextViewField = tabView.getClass().getDeclaredField("mTextView"); mTextViewField.setAccessible(true); TextView mTextView = (TextView) mTextViewField.get(tabView); tabView.setPadding(0, 5, 0, 5); Int width = 0; int width = 0; width = mTextView.getWidth()+20; if (width == 0) { mTextView.measure(0, 0); width = mTextView.getMeasuredWidth(); } / / Settings TAB spacing of 10 dp notice here cannot use Padding around because the width of the source line is set up according to the width of the tabView LinearLayout. LayoutParams params = (LinearLayout.LayoutParams) tabView.getLayoutParams(); params.width = width ; params.leftMargin = dp10; params.rightMargin = dp10; tabView.setLayoutParams(params); tabView.invalidate(); } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }}}); }}Copy the code

Change the underline height of the TabLayout

TabIndicatorHeight =”3dp”

<android.support.design.widget.TabLayout
        android:id="@+id/tablayout"
        android:layout_width="0dp"
        android:layout_height="0dp"     
        app:tabIndicatorHeight="3dp"/>
Copy the code

Share with you

I want to work my way up

Fly forward on the blades at the highest point

Let the wind blow dry tears and sweat

I want to work my way up

Waiting for the sun to watch its face

Little days have big dreams

I have my day

Let the wind blow dry tears and sweat

One day I will have my day