@@ -67,6 +67,7 @@ public class SmartTabLayout extends HorizontalScrollView {
67
67
private static final int TAB_VIEW_TEXT_SIZE_SP = 12 ;
68
68
private static final int TAB_VIEW_TEXT_COLOR = 0xFC000000 ;
69
69
private static final int TAB_VIEW_TEXT_MIN_WIDTH = 0 ;
70
+ private static final boolean TAB_CLICKABLE = true ;
70
71
71
72
protected final SmartTabStrip tabStrip ;
72
73
private int titleOffset ;
@@ -80,6 +81,7 @@ public class SmartTabLayout extends HorizontalScrollView {
80
81
private ViewPager .OnPageChangeListener viewPagerPageChangeListener ;
81
82
private OnScrollChangeListener onScrollChangeListener ;
82
83
private TabProvider tabProvider ;
84
+ private TabClickListener tabClickListener ;
83
85
private boolean distributeEvenly ;
84
86
85
87
public SmartTabLayout (Context context ) {
@@ -109,6 +111,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
109
111
boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY ;
110
112
int customTabLayoutId = NO_ID ;
111
113
int customTabTextViewId = NO_ID ;
114
+ boolean clickable = TAB_CLICKABLE ;
112
115
113
116
TypedArray a = context .obtainStyledAttributes (
114
117
attrs , R .styleable .stl_SmartTabLayout , defStyle , 0 );
@@ -130,6 +133,8 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
130
133
R .styleable .stl_SmartTabLayout_stl_customTabTextViewId , customTabTextViewId );
131
134
distributeEvenly = a .getBoolean (
132
135
R .styleable .stl_SmartTabLayout_stl_distributeEvenly , distributeEvenly );
136
+ clickable = a .getBoolean (
137
+ R .styleable .stl_SmartTabLayout_stl_clickable , clickable );
133
138
a .recycle ();
134
139
135
140
this .titleOffset = (int ) (TITLE_OFFSET_DIPS * density );
@@ -141,6 +146,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
141
146
this .tabViewTextSize = textSize ;
142
147
this .tabViewTextHorizontalPadding = textHorizontalPadding ;
143
148
this .tabViewTextMinWidth = textMinWidth ;
149
+ this .tabClickListener = clickable ? new TabClickListener () : null ;
144
150
this .distributeEvenly = distributeEvenly ;
145
151
146
152
if (customTabLayoutId != NO_ID ) {
@@ -362,7 +368,6 @@ protected TextView createDefaultTabView(CharSequence title) {
362
368
363
369
private void populateTabStrip () {
364
370
final PagerAdapter adapter = viewPager .getAdapter ();
365
- final OnClickListener tabClickListener = new TabClickListener ();
366
371
367
372
for (int i = 0 ; i < adapter .getCount (); i ++) {
368
373
@@ -380,7 +385,10 @@ private void populateTabStrip() {
380
385
lp .weight = 1 ;
381
386
}
382
387
383
- tabView .setOnClickListener (tabClickListener );
388
+ if (tabClickListener != null ) {
389
+ tabView .setOnClickListener (tabClickListener );
390
+ }
391
+
384
392
tabStrip .addView (tabView );
385
393
386
394
if (i == viewPager .getCurrentItem ()) {
0 commit comments