Last active
March 20, 2016 13:39
-
-
Save elsennov/398aa8f62c2d244923f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.novraditya.elsen.tablayoutexample; | |
import android.content.Context; | |
import android.support.design.widget.TabLayout; | |
import android.util.AttributeSet; | |
import java.lang.reflect.Field; | |
/** | |
* Created by elsennovraditya on 3/20/16. | |
*/ | |
public class CustomTabLayout extends TabLayout { | |
private static final int WIDTH_INDEX = 0; | |
private static final int DIVIDER_FACTOR = 3; | |
private static final String SCROLLABLE_TAB_MIN_WIDTH = "mScrollableTabMinWidth"; | |
public CustomTabLayout(Context context) { | |
super(context); | |
initTabMinWidth(); | |
} | |
public CustomTabLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
initTabMinWidth(); | |
} | |
public CustomTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
initTabMinWidth(); | |
} | |
private void initTabMinWidth() { | |
int[] wh = Utils.getScreenSize(getContext()); | |
int tabMinWidth = wh[WIDTH_INDEX] / DIVIDER_FACTOR; | |
Field field; | |
try { | |
field = TabLayout.class.getDeclaredField(SCROLLABLE_TAB_MIN_WIDTH); | |
field.setAccessible(true); | |
field.set(this, tabMinWidth); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment