gpt4 book ai didi

android - 为什么 switch 的 textOn 和 textOff 不显示?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:54 26 4
gpt4 key购买 nike

我正在尝试制作一个带有开/关开关的 ListView 。我找到了这个简单的代码,但问题是它对我不起作用。

<Switch
android:id="@+id/itemListSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Vibrate on"
android:textOff="Vibrate off"/>

是的,它显示了一个开关,但没有显示文本(振动开/关)。只显示一个可以切换的圆圈。我想发布屏幕截图,但不允许我这样做,因为我缺乏声誉。谁能告诉我为什么,因为我试图找到答案,但上面的简单代码对他们有用。如果有帮助,我的Android手机版本是5.0.2。提前致谢!

最佳答案

首先,您应该使用 SwitchCompat 以使其与所有 android 版本兼容,并拥有漂亮的 switch Material 设计外观。

回到您的问题,您缺少用于显示文本的属性 -app:showText -,这是一个示例:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
...>
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_compat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="25dp"
android:checked="false"
android:textOff="OFF"
android:textOn="ON"
app:showText="true"/>
</RelativeLayout>

关于android - 为什么 switch 的 textOn 和 textOff 不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30726017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com