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"><sizeandroid:width="30dp"android:height="30dp"></size><solidandroid:color="@android:color/white"></solid></shape>
switch_thumb增加透明边框
<strokeandroid: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"><solidandroid:color="@color/businesstop"></solid><cornersandroid: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"><solidandroid:color="@android:color/darker_gray"></solid><cornersandroid: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"><itemandroid:state_checked="true"android:drawable="@drawable/switch_track_on"></item><itemandroid:state_checked="false"android:drawable="@drawable/switch_track_off"></item>
</selector>
5、layout.xml下switch引用自定义滑动点和样式即可
<Switchandroid: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"/>