隐藏android开关按钮的默认文本
在我的Android应用程序中,我使用了一个切换按钮。是否仍有隐藏开关按钮文本的方法?对于API级别21,有一个隐藏选项(android:showText),但我需要在较低级别的设备上运行它 这是我的xml文件:隐藏android开关按钮的默认文本,android,button,switch-statement,Android,Button,Switch Statement,在我的Android应用程序中,我使用了一个切换按钮。是否仍有隐藏开关按钮文本的方法?对于API级别21,有一个隐藏选项(android:showText),但我需要在较低级别的设备上运行它 这是我的xml文件: <Switch android:layout_width="100dp" android:layout_height="wrap_content" android:layout_centerHorizontal="true"
<Switch
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:background="@drawable/offbuttonbg"
android:textAppearance="@style/SwitchTextAppearance"
android:thumb="@drawable/switchselector" />
对于较低版本,要隐藏文本,请使用
<Switch
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:textOff=""
android:textOn=""
android:background="@drawable/offbuttonbg"
android:textAppearance="@style/SwitchTextAppearance"
android:thumb="@drawable/switchselector" />
您有两个选择,一个是通过编码,另一个是通过XML 通过代码:
yourSwitch.setTextOff("textWhenOff") //Sets the text when the component is not in checked state.
yourSwitch.setTextOn("textWhenOn") //Sets the text when the component is not in checked state.
XML
<Switch
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:textOff="The text for the component when it's not checked."
android:textOn="The text for the component when it's checked."
android:background="@drawable/offbuttonbg"
android:textAppearance="@style/SwitchTextAppearance"
android:thumb="@drawable/switchselector" />
如果您需要更多信息,请始终参考。设置空字符串为textOff,textOn…,可能是…最简单的解决方案…我同意,请参见下面的示例答案。是的,我知道了,非常愚蠢的问题,无论如何,感谢您的快速响应用户想要隐藏文本我同意这就是为什么设置textOff和textOn的解决方案适用于这种情况,再看看你的建议,你的建议是一样的,只是对于XML,我给出了代码和XML两种形式,没有理由在这里否决投票。我的答案有什么问题?