Skip to content

Commit 6752ff5

Browse files
committed
Add README.md
1 parent 2b29832 commit 6752ff5

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Android-DayNightSwitch
2+
3+
Simple and Customizable Android Day Night Switch Widget
4+
5+
![Slider](/images/example.gif?raw=true "Example 1")
6+
7+
You can find examples in **example** project.
8+
9+
![Sliders](/images/examples.png?raw=true "Example 2")
10+
11+
## How to install
12+
13+
1. Add Jitpack.io repository in your root __build.gradle__ file
14+
15+
```gradle
16+
allprojects {
17+
repositories {
18+
// ...
19+
maven { url 'https://jitpack.io' }
20+
}
21+
}
22+
```
23+
24+
2. Add dependency in your module __build.gradle__ file
25+
26+
```gradle
27+
dependencies {
28+
implementation 'com.github.MasterAlish:Android-DayNightSwitch:v0.1'
29+
}
30+
```
31+
32+
## How to Use
33+
34+
1. Add __DayNightSwitch__ in the xml file
35+
36+
```xml
37+
<ma.apps.widgets.daynightswitch.DayNightSwitch
38+
android:id="@+id/switch_1"
39+
android:layout_width="120dp"
40+
android:layout_height="50dp"
41+
app:sliderColor="#F49044"
42+
app:sliderPadding="7dp" />
43+
```
44+
45+
2. Get the reference
46+
47+
```kotlin
48+
val switch1 = findViewById<DayNightSwitch>(R.id.switch_1)
49+
```
50+
51+
3. Listen for updates
52+
53+
```kotlin
54+
switch1.setOnSwitchListener { switch, isDayChecked ->
55+
// Do smth ...
56+
}
57+
```
58+
59+
4. Getting current state
60+
61+
```kotlin
62+
val daySelected: Boolean = switch1.isDayChecked()
63+
```
64+
65+
5. Setting state
66+
67+
```kotlin
68+
switch1.setDayChecked(true, animated = true)
69+
// or
70+
switch1.setDayChecked(true, animated = false)
71+
```
72+
73+
## Customization: Xml attributes
74+
75+
```xml
76+
<ma.apps.widgets.daynightswitch.DayNightSwitch
77+
android:id="@+id/switch_0"
78+
android:layout_width="115dp"
79+
android:layout_height="69dp"
80+
app:dayImage="@drawable/day_3" <!-- Background drawable for Day state -->
81+
app:nightImage="@drawable/night_3" <!-- Background drawable for Night state -->
82+
app:slideDuration="500" <!-- Sliding Animation duration -->
83+
app:sliderColor="#FFFFFF" <!-- Slider color -->
84+
app:sliderPadding="4dp" <!-- Padding for slider -->
85+
app:isDayChecked="false"/> <!-- Initial state -->
86+
```
87+

images/example.gif

824 KB
Loading

images/examples.png

112 KB
Loading

0 commit comments

Comments
 (0)