Android如何创建显示文本的开关,如何打开和关闭?

android how to create a switch with showing text on and off how?

提问人:Malo 提问时间:11/17/2023 更新时间:11/17/2023 访问量:21

问:

我想在我的 Android 应用程序中创建一个开关或切换开关,以打开和关闭文本,就我而言,我使用它

 <Switch
            android:id="@+id/it_radio_group"
            style="@style/RectangularSwitchStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginStart="5dp"
            android:showText="true"
            android:switchTextAppearance="@style/SwitchTextAppearanceOn"
            android:textOff="No"
            android:textOn="Yes"

            android:checked="false"
            android:textSize="16sp"
            android:thumb="@drawable/rectangle_switch_thumb"
            android:track="@drawable/rectangle_switch" />

开关如下图所示enter image description here

我也想显示文本“是”,并使其默认不被点击,我没有通过搜索找到任何东西

switch-语句 android-switch android-togglebutton

评论

0赞 tomerpacific 11/19/2023
这可能会有所帮助。

答: 暂无答案