diff --git a/README.md b/README.md
index 19aa47a..58c5063 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,36 @@
# Android PagerSlidingTabStrip
+## NEW UPDATE
+```Java
+public static final int INDICATOR_MODE_UNDERLINE = 0x1;
+public static final int INDICATOR_MODE_BACKGROUND = 0x2;
+```
+* INDICATOR_MODE_UNDERLINE是原来的下划线的那种指示器
+* INDICATOR_MODE_BACKGROUND是新增的圆角矩形背景的指示器
+
+--
+![](https://github.com/flyfly121/PagerSlidingTabStrip/blob/master/example.gif)
+
+## HOW TO USE
+```Java
+tabs.setIndicatorMode(PagerSlidingTabStrip.INDICATOR_MODE_BACKGROUND);
+```
+====
+原来下划线那种形式的指示器添加了几个新属性(请注意下面的图片,解释了几个关键词):
+```xml
+
+
+
+```
+* 第一个是指示器Indicator的左右边距
+* 第二个是指示器Indicator的宽与TabText的宽相等,也就是alignLeft & alignRight
+* 第三个是指示器Indicator的宽超出TabText的宽的距离
+
+--
+![](https://github.com/flyfly121/PagerSlidingTabStrip/blob/master/important_information.png)
+
+====
+
Interactive paging indicator widget, compatible with the `ViewPager` from the
Android Support Library.
diff --git a/example.gif b/example.gif
new file mode 100644
index 0000000..3b8658e
Binary files /dev/null and b/example.gif differ
diff --git a/example.png b/example.png
new file mode 100644
index 0000000..f96be93
Binary files /dev/null and b/example.png differ
diff --git a/example_small.png b/example_small.png
new file mode 100644
index 0000000..a1b3b7a
Binary files /dev/null and b/example_small.png differ
diff --git a/git_help.txt b/git_help.txt
new file mode 100644
index 0000000..ef06108
--- /dev/null
+++ b/git_help.txt
@@ -0,0 +1,42 @@
+usage: git [--version] [--help] [-C ] [-c name=value]
+ [--exec-path[=]] [--html-path] [--man-path] [--info-path]
+ [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
+ [--git-dir=] [--work-tree=] [--namespace=]
+ []
+
+These are common Git commands used in various situations:
+
+start a working area (see also: git help tutorial)
+ clone Clone a repository into a new directory
+ init Create an empty Git repository or reinitialize an existing one
+
+work on the current change (see also: git help everyday)
+ add Add file contents to the index
+ mv Move or rename a file, a directory, or a symlink
+ reset Reset current HEAD to the specified state
+ rm Remove files from the working tree and from the index
+
+examine the history and state (see also: git help revisions)
+ bisect Use binary search to find the commit that introduced a bug
+ grep Print lines matching a pattern
+ log Show commit logs
+ show Show various types of objects
+ status Show the working tree status
+
+grow, mark and tweak your common history
+ branch List, create, or delete branches
+ checkout Switch branches or restore working tree files
+ commit Record changes to the repository
+ diff Show changes between commits, commit and working tree, etc
+ merge Join two or more development histories together
+ rebase Reapply commits on top of another base tip
+ tag Create, list, delete or verify a tag object signed with GPG
+
+collaborate (see also: git help workflows)
+ fetch Download objects and refs from another repository
+ pull Fetch from and integrate with another repository or a local branch
+ push Update remote refs along with associated objects
+
+'git help -a' and 'git help -g' list available subcommands and some
+concept guides. See 'git help ' or 'git help '
+to read about a specific subcommand or concept.
diff --git a/important_information.png b/important_information.png
new file mode 100644
index 0000000..0fd431b
Binary files /dev/null and b/important_information.png differ
diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml
index 18b6be8..d0f9627 100644
--- a/library/res/values/attrs.xml
+++ b/library/res/values/attrs.xml
@@ -6,6 +6,9 @@
+
+
+
@@ -15,4 +18,4 @@
-
\ No newline at end of file
+
diff --git a/library/src/com/astuetz/PagerSlidingTabStrip.java b/library/src/com/astuetz/PagerSlidingTabStrip.java
index 87b671c..8325bc3 100644
--- a/library/src/com/astuetz/PagerSlidingTabStrip.java
+++ b/library/src/com/astuetz/PagerSlidingTabStrip.java
@@ -53,9 +53,12 @@ public interface IconTabProvider {
private static final int[] ATTRS = new int[] {
android.R.attr.textSize,
android.R.attr.textColor
- };
+ };
// @formatter:on
+ public static final int INDICATOR_MODE_UNDERLINE = 0x1;
+ public static final int INDICATOR_MODE_BACKGROUND = 0x2;
+
private LinearLayout.LayoutParams defaultTabLayoutParams;
private LinearLayout.LayoutParams expandedTabLayoutParams;
@@ -72,7 +75,8 @@ public interface IconTabProvider {
private Paint rectPaint;
private Paint dividerPaint;
-
+ private RectF indicatorRectF;
+
private int indicatorColor = 0xFF666666;
private int underlineColor = 0x1A000000;
private int dividerColor = 0x1A000000;
@@ -82,6 +86,10 @@ public interface IconTabProvider {
private int scrollOffset = 52;
private int indicatorHeight = 8;
+ private int indicatorMarginLeftRight = 0;
+ private boolean indicatorAlignTabTextLeftRight = false;
+ private int indicatorOverflowTabText = 0;
+ private int indicatorBgPadding = 10;
private int underlineHeight = 2;
private int dividerPadding = 12;
private int tabPadding = 24;
@@ -121,11 +129,14 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
+ indicatorMarginLeftRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorMarginLeftRight, dm);
+ indicatorOverflowTabText = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorOverflowTabText, dm);
underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
+ indicatorBgPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorBgPadding, dm);
// get system attrs (android:textSize and android:textColor)
@@ -144,6 +155,9 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
+ indicatorMarginLeftRight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorMarginLeftRight, indicatorMarginLeftRight);
+ indicatorAlignTabTextLeftRight = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsIndicatorAlignTabTextLeftRight, indicatorAlignTabTextLeftRight);
+ indicatorOverflowTabText = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorOverflowTabText, indicatorOverflowTabText);
underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding);
tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
@@ -162,6 +176,8 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
dividerPaint.setAntiAlias(true);
dividerPaint.setStrokeWidth(dividerWidth);
+ indicatorRectF = new RectF();
+
defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
@@ -333,9 +349,30 @@ protected void onDraw(Canvas canvas) {
lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
}
-
- canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
-
+
+ Paint p = ((TextView) currentTab).getPaint();
+ String text = ((TextView)currentTab).getText().toString();
+ text = textAllCaps ? text.toUpperCase(locale) : text;
+ float textLength = p.measureText(text);
+
+ if (indicatorOverflowTabText > 0 || indicatorAlignTabTextLeftRight) {
+ if (currentTab instanceof TextView) {
+ // minus the length of indicatorOverflowTabText
+ indicatorMarginLeftRight = (int) ((currentTab.getWidth() - textLength) / 2 - indicatorOverflowTabText);
+ }
+ }
+
+ // left and right changed
+ if (indicatorMode == INDICATOR_MODE_UNDERLINE) {
+ canvas.drawRect(lineLeft + indicatorMarginLeftRight, height - indicatorHeight, lineRight - indicatorMarginLeftRight, height, rectPaint);
+ } else if (indicatorMode == INDICATOR_MODE_BACKGROUND) {
+ indicatorRectF.left = lineLeft + (currentTab.getWidth() - textLength) / 2 - indicatorBgPadding;
+ indicatorRectF.top = indicatorHeight;
+ indicatorRectF.right = lineRight - (currentTab.getWidth() - textLength) / 2 + indicatorBgPadding;
+ indicatorRectF.bottom = height - indicatorHeight;
+ float r = (lineRight - 2 * indicatorHeight) / 2;
+ canvas.drawRoundRect(indicatorRectF, r, r, rectPaint);
+ }
// draw underline
rectPaint.setColor(underlineColor);
@@ -387,6 +424,14 @@ public void onPageSelected(int position) {
}
+ public int getIndicatorMode() {
+ return indicatorMode;
+ }
+
+ public void setIndicatorMode(int indicatorMode) {
+ this.indicatorMode = indicatorMode;
+ }
+
public void setIndicatorColor(int indicatorColor) {
this.indicatorColor = indicatorColor;
invalidate();
@@ -410,6 +455,31 @@ public int getIndicatorHeight() {
return indicatorHeight;
}
+ public int getIndicatorMarginLeftRight() {
+ return indicatorMarginLeftRight;
+ }
+
+ public void setIndicatorMarginLeftRight(int indicatorMarginLeftRight) {
+ this.indicatorMarginLeftRight = indicatorMarginLeftRight;
+ }
+
+ public boolean isIndicatorAlignTabTextLeftRight() {
+ return indicatorAlignTabTextLeftRight;
+ }
+
+ public void setIndicatorAlignTabTextLeftRight(
+ boolean indicatorAlignTabTextLeftRight) {
+ this.indicatorAlignTabTextLeftRight = indicatorAlignTabTextLeftRight;
+ }
+
+ public int getIndicatorBgPadding() {
+ return indicatorBgPadding;
+ }
+
+ public void setIndicatorBgPadding(int indicatorBgPadding) {
+ this.indicatorBgPadding = indicatorBgPadding;
+ }
+
public void setUnderlineColor(int underlineColor) {
this.underlineColor = underlineColor;
invalidate();
diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt"
new file mode 100644
index 0000000..73ca99b
--- /dev/null
+++ "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt"
@@ -0,0 +1,2 @@
+һ
+public static final main