diff --git a/README.md b/README.md index 66f6906..2a68d2c 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,16 @@ app:slider_icon="@drawable/custom_icon" You can also disable the rotation by setting the ``rotate_icon`` attribute to false. +#### ``slider_icon_color`` + +You can set a custom color for the icon by setting the ``slider_icon_color`` attribute. + +
+ +
+ +This attribute defaults to the ``outer_color`` if set. If ``outer_color`` is not set, this attribute defaults to **colorAccent** from your theme. + #### ``android:elevation`` Use the ``android:elevation`` attribute to set the **elevation** of the widget. The widgets will take care of providing the proper ``ViewOutlineProvider`` during the whole animation (a.k.a. The shadow will be drawn properly). diff --git a/assets/slider_icon_color.png b/assets/slider_icon_color.png new file mode 100644 index 0000000..ad60220 Binary files /dev/null and b/assets/slider_icon_color.png differ diff --git a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt index 68d1586..6421dff 100644 --- a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt +++ b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt @@ -14,7 +14,6 @@ import android.support.annotation.RequiresApi import android.support.graphics.drawable.AnimatedVectorDrawableCompat import android.support.graphics.drawable.VectorDrawableCompat import android.support.v4.content.ContextCompat -import android.support.v4.graphics.ColorUtils import android.support.v4.widget.TextViewCompat import android.util.AttributeSet import android.util.TypedValue @@ -90,12 +89,11 @@ class SlideToActView @JvmOverloads constructor ( } } - /** Outer color used by the slider (primary) */ + /** Outer color used by the slider (primary)*/ var outerColor: Int = 0 set(value) { field = value mOuterPaint.color = value - mDrawableArrow.setTint(value) invalidate() } @@ -115,6 +113,14 @@ class SlideToActView @JvmOverloads constructor ( invalidate() } + /** Custom Icon color */ + var iconColor: Int = 0 + set(value) { + field = value + mDrawableArrow.setTint(value) + invalidate() + } + /** Slider cursor position (between 0 and (`reaWidth - mAreaHeight)) */ private var mPosition: Int = 0 set(value) { @@ -213,6 +219,7 @@ class SlideToActView @JvmOverloads constructor ( val actualOuterColor : Int val actualInnerColor : Int val actualTextColor : Int + val actualIconColor : Int mTextView = TextView(context) mTextPaint = mTextView.paint @@ -258,6 +265,16 @@ class SlideToActView @JvmOverloads constructor ( mActualAreaMargin = mOriginAreaMargin mIcon = layoutAttrs.getResourceId(R.styleable.SlideToActView_slider_icon, R.drawable.ic_arrow) + + // For icon color. check if the `slide_icon_color` is set. + // if not check if the `outer_color` is set. + // if not, default to defaultOuter. + actualIconColor = when { + layoutAttrs.hasValue(R.styleable.SlideToActView_slider_icon_color) -> + layoutAttrs.getColor(R.styleable.SlideToActView_slider_icon_color, defaultOuter) + layoutAttrs.hasValue(R.styleable.SlideToActView_outer_color) -> actualOuterColor + else -> defaultOuter + } } finally { layoutAttrs.recycle() } @@ -281,6 +298,7 @@ class SlideToActView @JvmOverloads constructor ( outerColor = actualOuterColor innerColor = actualInnerColor + iconColor = actualIconColor mIconMargin = context.resources.getDimensionPixelSize(R.dimen.default_icon_margin) mArrowMargin = mIconMargin diff --git a/slidetoact/src/main/res/values/attrs.xml b/slidetoact/src/main/res/values/attrs.xml index fd541bf..2e9fbce 100644 --- a/slidetoact/src/main/res/values/attrs.xml +++ b/slidetoact/src/main/res/values/attrs.xml @@ -16,6 +16,7 @@