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"> - +