发布于 2022-11-18 09:42:51
‘com.github.GwanHyeok:StickySwitch:0.0.16’
<io.ghyeok.stickyswitch.widget.StickySwitch
android:id="@+id/sticky_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:ss_animationDuration="600"
app:ss_iconPadding="18dp"
app:ss_iconSize="22dp"
app:ss_leftIcon="@drawable/ic_male"
app:ss_leftText="Male"
app:ss_rightIcon="@drawable/ic_female"
app:ss_rightText="Female"
app:ss_selectedTextSize="14sp"
app:ss_sliderBackgroundColor="@color/colorSliderBackground"
app:ss_switchColor="@color/colorSwitchColor"
app:ss_textColor="@color/colorTextColor"
app:ss_textSize="12sp"
app:ss_animationType="line"/>
另一种方式,
在res/ toggle.xml中创建可绘制的
在“绘图”文件夹中添加您喜欢的“打开”和“关闭”图像
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/toggle_on" android:state_checked="true"/>
<item android:drawable="@drawable/toggle_off" android:state_checked="false"/>
</selector>
将选择器应用于切换按钮。
<ToggleButton
android:id="@+id/chkState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/toggle_selector"
android:textOff=""
android:textOn=""/>
删除我在上面代码中使用的文本
textOff=""
textOn=""
如果您有任何疑问,请评论
https://stackoverflow.com/questions/74487532
复制相似问题