StickySwitch
介绍:
一个沾粘效果的滑动开关。
运行效果:
使用说明:
Requirements
-
Android SDK 15+
root build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependency
dependencies {
compile 'com.github.GwonHyeok:StickySwitch:0.0.3'
}
xml
<io.ghyeok.stickyswitch.widget.StickySwitch
android:layout_width="160dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
app:iconPadding="18dp"
app:iconSize="22dp"
app:leftIcon="@drawable/ic_male"
app:leftText="Male"
app:rightIcon="@drawable/ic_female"
app:rightText="Female"
app:selectedTextSize="14sp"
app:textSize="12sp" />
属性
Name | Type | Description |
---|---|---|
iconPadding | dimension | - |
iconSize | dimension | - |
leftIcon | integer | - |
leftText | string | - |
rightIcon | integer | - |
rightText | string | - |
selectedTextSize | dimension | - |
textSize | dimension | - |
|
Status change notification
StickySwitch.Direction有两个值(LEFT, RIGHT);
当你点击开关的时候onSelectedChange方法被调用。
开关滑动到右边时,direction的值是StickySwitch.Direction.RIGHT
滑动到左边时,值是StickySwitch.Direction.LEFT
Java Code Example
// Set Selected Change Listener
StickySwitch stickySwitch = (StickySwitch) findViewById(R.id.sticky_switch);
stickySwitch.setOnSelectedChangeListener(new StickySwitch.OnSelectedChangeListener() {
@Override
public void onSelectedChange(@NotNull StickySwitch.Direction direction) {
Log.d(TAG, "Now Selected : " + direction.name());
}
});
Set, Get Direction Programmatically
// if you want switch button direction to left
stickySwitch.setDirection(StickySwitch.Direction.LEFT);
// Get current Direction
stickySwitch.getDirection(); // StickySwitch.Direction.LEFT
已下载
0