gpt4 book ai didi

Android Switch 小部件 textOn 和 textOff 在 Lollipop 中不起作用

转载 作者:IT王子 更新时间:2023-10-28 23:44:22 28 4
gpt4 key购买 nike

Lollipop (5.0) 中开关小部件的行为发生了变化。

    <Switch
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@id/another_view"
android:layout_toRightOf="@id/another_view"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:textOff="@string/disabled"
android:textOn="@string/enabled"
android:fontFamily="sans-serif-condensed"
/>

targetSdkVersion=19 时渲染的开关:

enter image description here

targetSdkVersion=21 时渲染的开关:

enter image description here

请注意,Android Studio 中的预览渲染仍会生成带有文本的开关,但当使用 targetSdkVersion=21 构建的 apk 在具有 Lollipop (Nexus 5) 的设备上运行时,该开关会丢失其文本。在同一个 Lollipop 设备上运行使用 targetSdkVersion=19 构建的 apk 会按预期正确呈现开关。

为什么?有什么建议的解决方法吗?

最佳答案

默认情况下,Material 主题下不显示文本,因为切换小部件 Assets 不适用于文本。您设置的任何文本都将用于向无障碍服务描述内容。

您可以使用 android:showText 更改此设置属性(property)或 Switch.setShowText(boolean)方法。

<Switch
...
android:showText="true" />

如果您使用 AppCompat 开关,请改用 app:showText

关于Android Switch 小部件 textOn 和 textOff 在 Lollipop 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276054/

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