-
Notifications
You must be signed in to change notification settings - Fork 1
/
FontTabLayout.java
54 lines (44 loc) · 1.58 KB
/
FontTabLayout.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.example.jeffreynyauke.myapplication.utils;
import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* Created by Jeffrey Nyauke on 2/19/2017.
*/
public class FontTabLayout extends TabLayout {
private static final String FONT_PATH = "fonts/Lato-Regular.ttf";
private Typeface mTypeface;
public FontTabLayout (Context context){
super(context);
init();
}
public FontTabLayout (Context context, AttributeSet attrs){
super(context, attrs);
init();
}
public FontTabLayout (Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
init();
}
private void init(){
mTypeface = Typeface.createFromAsset(getContext().getAssets(), FONT_PATH);
}
@Override
public void addTab(@NonNull Tab tab, int position, boolean setSelected){
super.addTab(tab, position, setSelected);
ViewGroup mainView = (ViewGroup) getChildAt(0);
ViewGroup tabView = (ViewGroup) mainView.getChildAt(tab.getPosition());
int tabChildCount = tabView.getChildCount();
for (int i = 0; i < tabChildCount; i++){
View tabViewChild = tabView.getChildAt(i);
if (tabViewChild instanceof TextView){
((TextView) tabViewChild).setTypeface(mTypeface, Typeface.NORMAL);
}
}
}
}