Skip to content

Commit 795a9b8

Browse files
committed
Add stl_clickable attribute.
1 parent 4ceb82c commit 795a9b8

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ This should usually be placed above the ViewPager it represents.
6666
app:stl_defaultTabTextHorizontalPadding="16dp"
6767
app:stl_defaultTabTextMinWidth="0dp"
6868
app:stl_distributeEvenly="false"
69+
app:stl_clickable="true"
6970
/>
7071

7172
<android.support.v4.view.ViewPager
@@ -147,6 +148,7 @@ There are several attributes you can set:
147148
| stl_customTabTextLayoutId | Layout ID defined custom tab. If you do not specify a layout, use the default tab |
148149
| stl_customTabTextViewId | Text view ID in a custom tab layout. If you do not define with customTabTextLayoutId, does not work |
149150
| stl_distributeEvenly | If set to true, each tab is given the same weight, default false |
151+
| stl_clickable | If set to false, disable the selection of a tab click, default true |
150152

151153

152154
*__Notes:__ Both 'stl_indicatorAlwaysInCenter' and 'stl_distributeEvenly' if it is set to true, it will throw UnsupportedOperationException.*
@@ -187,7 +189,7 @@ public class SmartTabLayout extends HorizontalScrollView {
187189

188190
# How to use the utility
189191

190-
Utility has two types available to suit the Android support library.
192+
Utility has two types available to suit the Android support library.
191193

192194
* utils-v4 library contains the PagerAdapter implementation class for _android.support.v4.app.Fragment_
193195
* utils-v13 library contains the PagerAdapter implementation class for _android.app.Fragment_
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<com.ogaclejapan.smarttablayout.SmartTabLayout
2-
xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:id="@id/viewpagertab"
5-
android:layout_width="wrap_content"
6-
android:layout_height="16dp"
7-
android:layout_gravity="bottom|center_horizontal"
8-
app:stl_customTabTextLayoutId="@layout/custom_tab_circle"
9-
app:stl_dividerColor="@color/transparent"
10-
app:stl_dividerThickness="0dp"
11-
app:stl_indicatorColor="@color/accent"
12-
app:stl_indicatorCornerRadius="4dp"
13-
app:stl_indicatorInterpolation="linear"
14-
app:stl_indicatorGravity="center"
15-
app:stl_indicatorThickness="8dp"
16-
app:stl_underlineColor="@color/transparent"
17-
app:stl_underlineThickness="0dp"
18-
/>
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@id/viewpagertab"
5+
android:layout_width="wrap_content"
6+
android:layout_height="16dp"
7+
android:layout_gravity="bottom|center_horizontal"
8+
app:stl_clickable="false"
9+
app:stl_customTabTextLayoutId="@layout/custom_tab_circle"
10+
app:stl_dividerColor="@color/transparent"
11+
app:stl_dividerThickness="0dp"
12+
app:stl_indicatorColor="@color/accent"
13+
app:stl_indicatorCornerRadius="4dp"
14+
app:stl_indicatorGravity="center"
15+
app:stl_indicatorInterpolation="linear"
16+
app:stl_indicatorThickness="8dp"
17+
app:stl_underlineColor="@color/transparent"
18+
app:stl_underlineThickness="0dp"
19+
/>
1920

2021

library/src/main/java/com/ogaclejapan/smarttablayout/SmartTabLayout.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class SmartTabLayout extends HorizontalScrollView {
6767
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
6868
private static final int TAB_VIEW_TEXT_COLOR = 0xFC000000;
6969
private static final int TAB_VIEW_TEXT_MIN_WIDTH = 0;
70+
private static final boolean TAB_CLICKABLE = true;
7071

7172
protected final SmartTabStrip tabStrip;
7273
private int titleOffset;
@@ -80,6 +81,7 @@ public class SmartTabLayout extends HorizontalScrollView {
8081
private ViewPager.OnPageChangeListener viewPagerPageChangeListener;
8182
private OnScrollChangeListener onScrollChangeListener;
8283
private TabProvider tabProvider;
84+
private TabClickListener tabClickListener;
8385
private boolean distributeEvenly;
8486

8587
public SmartTabLayout(Context context) {
@@ -109,6 +111,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
109111
boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
110112
int customTabLayoutId = NO_ID;
111113
int customTabTextViewId = NO_ID;
114+
boolean clickable = TAB_CLICKABLE;
112115

113116
TypedArray a = context.obtainStyledAttributes(
114117
attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
@@ -130,6 +133,8 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
130133
R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId);
131134
distributeEvenly = a.getBoolean(
132135
R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
136+
clickable = a.getBoolean(
137+
R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
133138
a.recycle();
134139

135140
this.titleOffset = (int) (TITLE_OFFSET_DIPS * density);
@@ -141,6 +146,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
141146
this.tabViewTextSize = textSize;
142147
this.tabViewTextHorizontalPadding = textHorizontalPadding;
143148
this.tabViewTextMinWidth = textMinWidth;
149+
this.tabClickListener = clickable ? new TabClickListener() : null;
144150
this.distributeEvenly = distributeEvenly;
145151

146152
if (customTabLayoutId != NO_ID) {
@@ -362,7 +368,6 @@ protected TextView createDefaultTabView(CharSequence title) {
362368

363369
private void populateTabStrip() {
364370
final PagerAdapter adapter = viewPager.getAdapter();
365-
final OnClickListener tabClickListener = new TabClickListener();
366371

367372
for (int i = 0; i < adapter.getCount(); i++) {
368373

@@ -380,7 +385,10 @@ private void populateTabStrip() {
380385
lp.weight = 1;
381386
}
382387

383-
tabView.setOnClickListener(tabClickListener);
388+
if (tabClickListener != null) {
389+
tabView.setOnClickListener(tabClickListener);
390+
}
391+
384392
tabStrip.addView(tabView);
385393

386394
if (i == viewPager.getCurrentItem()) {

library/src/main/res/values/attrs.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
<attr name="stl_customTabTextLayoutId" format="reference"/>
3434
<attr name="stl_customTabTextViewId" format="reference"/>
3535
<attr name="stl_distributeEvenly" format="boolean"/>
36+
<attr name="stl_clickable" format="boolean"/>
3637
</declare-styleable>
37-
</resources>
38+
</resources>

0 commit comments

Comments
 (0)