switch (changeFragmentEvent.getViewId()) { //启动设备(安卓接收) case 1: textView.setText("vvvvv555"+changeFragmentEvent.getstring()); break; case 2: textView.setText("vvvvv555WWW22"); break; }
效果
实现方法
1、drawable下创建滑动圆点 switch_thumb
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="30dp"
android:height="30dp">
</size>
<solid
android:color="@android:color/white">
</solid>
</shape>
switch_thumb增加透明边框
<stroke
android:width="9pt"
android:color="@color/transparent" />
2、drawable下创建选中样式 switch_track_on
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/businesstop">
</solid>
<corners
android:radius="30dp">
</corners>
</shape>
3、drawable下创建非选中样式 switch_track_off
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@android:color/darker_gray">
</solid>
<corners
android:radius="30dp">
</corners>
</shape>
4、drawable下创建switch样式 switch_track
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="@drawable/switch_track_on"></item>
<item
android:state_checked="false"
android:drawable="@drawable/switch_track_off"></item>
</selector>
5、layout.xml下switch引用自定义滑动点和样式即可
<Switch
android:id="@+id/ycsw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:thumb="@drawable/switch_thumb"
android:track="@drawable/switch_track"
android:gravity="center"/>