效果图:
代码:
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.blogtest.MainActivity">
<!--checked:是否处于开启状态-->
<!--textOff:关闭状态显示的文字-->
<!--textOn:开启状态显示的文字-->
<ToggleButton
android:layout_width="wrap_content"