Skip to content

Commit 779932b

Browse files
committed
Support setting background in styles. Closes JakeWharton#117.
1 parent 11c0f9e commit 779932b

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

library/res/values/vpi__attrs.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
<attr name="strokeColor" format="color" />
5252
<!-- Width of the stroke used to draw the circles. -->
5353
<attr name="strokeWidth" />
54+
<!-- View background -->
55+
<attr name="android:background"/>
5456
</declare-styleable>
5557

5658
<declare-styleable name="LinePageIndicator">
@@ -66,6 +68,8 @@
6668
<attr name="strokeWidth" />
6769
<!-- Width of the gap between each indicator line. -->
6870
<attr name="gapWidth" format="dimension" />
71+
<!-- View background -->
72+
<attr name="android:background"/>
6973
</declare-styleable>
7074

7175
<declare-styleable name="TitlePageIndicator">
@@ -99,6 +103,8 @@
99103
<attr name="titlePadding" format="dimension" />
100104
<!-- Padding between titles and the top of the View. -->
101105
<attr name="topPadding" format="dimension" />
106+
<!-- View background -->
107+
<attr name="android:background"/>
102108
</declare-styleable>
103109

104110
<declare-styleable name="UnderlinePageIndicator">
@@ -110,5 +116,7 @@
110116
<attr name="fadeLength" format="integer" />
111117
<!-- Color of the selected line that represents the current page. -->
112118
<attr name="selectedColor" />
119+
<!-- View background -->
120+
<attr name="android:background"/>
113121
</declare-styleable>
114122
</resources>

library/src/com/viewpagerindicator/CirclePageIndicator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.graphics.Canvas;
2323
import android.graphics.Paint;
2424
import android.graphics.Paint.Style;
25+
import android.graphics.drawable.Drawable;
2526
import android.os.Parcel;
2627
import android.os.Parcelable;
2728
import android.support.v4.view.MotionEventCompat;
@@ -101,6 +102,11 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
101102
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
102103
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
103104

105+
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
106+
if (background != null) {
107+
setBackgroundDrawable(background);
108+
}
109+
104110
a.recycle();
105111

106112
final ViewConfiguration configuration = ViewConfiguration.get(context);

library/src/com/viewpagerindicator/LinePageIndicator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.res.TypedArray;
2121
import android.graphics.Canvas;
2222
import android.graphics.Paint;
23+
import android.graphics.drawable.Drawable;
2324
import android.os.Parcel;
2425
import android.os.Parcelable;
2526
import android.support.v4.view.MotionEventCompat;
@@ -85,6 +86,11 @@ public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
8586
mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
8687
mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));
8788

89+
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
90+
if (background != null) {
91+
setBackgroundDrawable(background);
92+
}
93+
8894
a.recycle();
8995

9096
final ViewConfiguration configuration = ViewConfiguration.get(context);

library/src/com/viewpagerindicator/TitlePageIndicator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package com.viewpagerindicator;
1919

20-
import java.util.ArrayList;
2120
import android.content.Context;
2221
import android.content.res.Resources;
2322
import android.content.res.TypedArray;
@@ -26,6 +25,7 @@
2625
import android.graphics.Path;
2726
import android.graphics.Rect;
2827
import android.graphics.Typeface;
28+
import android.graphics.drawable.Drawable;
2929
import android.os.Parcel;
3030
import android.os.Parcelable;
3131
import android.support.v4.view.MotionEventCompat;
@@ -36,6 +36,8 @@
3636
import android.view.View;
3737
import android.view.ViewConfiguration;
3838

39+
import java.util.ArrayList;
40+
3941
/**
4042
* A TitlePageIndicator is a PageIndicator which displays the title of left view
4143
* (if exist), the title of the current select view (centered) and the title of
@@ -180,6 +182,11 @@ public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
180182
mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
181183
mPaintFooterIndicator.setColor(footerColor);
182184

185+
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
186+
if (background != null) {
187+
setBackgroundDrawable(background);
188+
}
189+
183190
a.recycle();
184191

185192
final ViewConfiguration configuration = ViewConfiguration.get(context);

library/src/com/viewpagerindicator/UnderlinePageIndicator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.res.TypedArray;
2121
import android.graphics.Canvas;
2222
import android.graphics.Paint;
23+
import android.graphics.drawable.Drawable;
2324
import android.os.Parcel;
2425
import android.os.Parcelable;
2526
import android.support.v4.view.MotionEventCompat;
@@ -97,6 +98,11 @@ public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle)
9798
setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
9899
setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));
99100

101+
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
102+
if (background != null) {
103+
setBackgroundDrawable(background);
104+
}
105+
100106
a.recycle();
101107

102108
final ViewConfiguration configuration = ViewConfiguration.get(context);

0 commit comments

Comments
 (0)