直播视频app源码,Android实现按钮打开关闭,颜色可自定义
直播视频app源码,Android实现按钮打开关闭,颜色可自定义
```cpp <Switch android:id="@+id/switch_shield_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="15dp" android:thumb="@drawable/chat_more_switch_selector" android:track="@drawable/chat_more_switch_nomal" /> ```
chat_more_switch_selector主要用来实现中间的圆
```cpp <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <shape android:shape="oval"> <!-- 圆的宽高--> <size android:width="16dp" android:height="16dp" /> <!-- 选中之后颜色--> <solid android:color="#C5C5C5" /> </shape> </item> <item> <shape android:shape="oval"> <!-- 圆的宽高--> <size android:width="16dp" android:height="16dp" /> <!-- 未选中默认颜色--> <solid android:color="#C5C5C5" /> </shape> </item> </selector> ```
chat_more_switch_nomal实现长方形圆
```cpp <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <shape android:shape="rectangle"> <!-- 长圆宽高--> <size android:width="32dp" android:height="16dp" /> <!-- 选中之后颜色白色--> <solid android:color="@color/main_bg" /> <corners android:radius="8dp" /> </shape> </item> <item> <shape android:shape="rectangle"> <!-- 长圆宽高--> <size android:width="32dp" android:height="16dp" /> <!-- 未选中默认颜色是灰色--> <solid android:color="#6D6D6D" /> <corners android:radius="8dp" /> </shape> </item> </selector> ```
监听选中未选中
```cpp switch_shield_msg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ }else{ } } }); ```
以上就是直播视频app源码,Android实现按钮打开关闭,颜色可自定义, 更多内容欢迎关注之后的文章
浙公网安备 33010602011771号