diff --git a/README.md b/README.md
index 21323d6..d7be3e5 100644
--- a/README.md
+++ b/README.md
@@ -220,6 +220,13 @@ You can set a custom icon by setting the ``slider_icon``attribute to a drawable
app:slider_icon="@drawable/custom_icon"
```
+You can also set a custom icon programmatically with the provided setter.
+
+```java
+SlideToActView sta = findViewById(R.id.slider);
+sta.setSliderIcon(R.drawable.custom_icon);
+```
+
You can also disable the rotation by setting the ``rotate_icon`` attribute to false.
#### ``slider_icon_color``
diff --git a/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java b/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
index ce8d7a0..2333307 100644
--- a/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
+++ b/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
@@ -64,6 +64,32 @@ protected void onCreate(Bundle savedInstanceState) {
break;
case R.id.button_custom_icon:
setContentView(R.layout.content_custom_icon);
+ final SlideToActView slider = findViewById(R.id.slide_custom_icon);
+ View.OnClickListener listener = new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ switch(v.getId()) {
+ case R.id.button_android_icon:
+ slider.setSliderIcon(R.drawable.ic_android);
+ break;
+ case R.id.button_cloud_icon:
+ slider.setSliderIcon(R.drawable.ic_cloud);
+ break;
+ default:
+ break;
+ }
+ }
+ };
+
+ slider.setOnSlideResetListener(new SlideToActView.OnSlideResetListener() {
+ @Override
+ public void onSlideReset(SlideToActView view) {
+ slider.setSliderIcon(R.drawable.custom_icon);
+ }
+ });
+
+ findViewById(R.id.button_android_icon).setOnClickListener(listener);
+ findViewById(R.id.button_cloud_icon).setOnClickListener(listener);
break;
case R.id.button_reversed_slider:
setContentView(R.layout.content_reversed_slider);
diff --git a/example/src/main/res/drawable/ic_android.xml b/example/src/main/res/drawable/ic_android.xml
new file mode 100644
index 0000000..fa2b135
--- /dev/null
+++ b/example/src/main/res/drawable/ic_android.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/example/src/main/res/drawable/ic_cloud.xml b/example/src/main/res/drawable/ic_cloud.xml
new file mode 100644
index 0000000..0f28023
--- /dev/null
+++ b/example/src/main/res/drawable/ic_cloud.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/example/src/main/res/layout/content_custom_icon.xml b/example/src/main/res/layout/content_custom_icon.xml
index 39abf22..53cc075 100644
--- a/example/src/main/res/layout/content_custom_icon.xml
+++ b/example/src/main/res/layout/content_custom_icon.xml
@@ -3,7 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
+
+
+
\ No newline at end of file
diff --git a/example/src/main/res/values/strings.xml b/example/src/main/res/values/strings.xml
index 6e02cc1..81c27d7 100644
--- a/example/src/main/res/values/strings.xml
+++ b/example/src/main/res/values/strings.xml
@@ -16,4 +16,6 @@
Bump Vibration
Event Log
Press the following buttons to checkout different SlideToActView and understand each parameter. You can reset the sliders pressing the Reset button in the Toolbar. Enjoy :)
+ Use Android icon
+ Use Cloud icon
diff --git a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
index df7f8c4..d748578 100644
--- a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
+++ b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
@@ -141,6 +141,17 @@ class SlideToActView @JvmOverloads constructor(
invalidate()
}
+ /** Custom Slider Icon */
+ var sliderIcon: Int = R.drawable.slidetoact_ic_arrow
+ set(value) {
+ field = value
+ if (field != 0) {
+ mDrawableArrow = parseVectorDrawableCompat(context.resources, value, context.theme)
+ mDrawableArrow.setTint(iconColor)
+ invalidate()
+ }
+ }
+
/** Slider cursor position (between 0 and (`mAreaWidth - mAreaHeight)) */
private var mPosition: Int = 0
set(value) {
@@ -190,15 +201,12 @@ class SlideToActView @JvmOverloads constructor(
private var mTickMargin: Int
/** Arrow drawable */
- private val mDrawableArrow: VectorDrawableCompat
+ private lateinit var mDrawableArrow: VectorDrawableCompat
/** Tick drawable, is actually an AnimatedVectorDrawable */
private val mDrawableTick: Drawable
private var mFlagDrawTick: Boolean = false
- /** The icon for the drawable */
- private var mIcon: Int = R.drawable.slidetoact_ic_arrow
-
/* -------------------- PAINT & DRAW -------------------- */
/** Paint used for outer elements */
private val mOuterPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
@@ -333,7 +341,7 @@ class SlideToActView @JvmOverloads constructor(
)
mActualAreaMargin = mOriginAreaMargin
- mIcon = getResourceId(
+ sliderIcon = getResourceId(
R.styleable.SlideToActView_slider_icon, R.drawable.slidetoact_ic_arrow
)
@@ -373,8 +381,6 @@ class SlideToActView @JvmOverloads constructor(
mAreaHeight.toFloat()
)
- mDrawableArrow = parseVectorDrawableCompat(context.resources, mIcon, context.theme)
-
// Due to bug in the AVD implementation in the support library, we use it only for API < 21
mDrawableTick = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
context.resources.getDrawable(