Android开关小部件的textOn和textOff文本始终以大写形式显示。无论如何,没有自定义xml文件就可以更改大小写吗?
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Switch"
android:textOff="@string/on"
android:textOn="@string/off"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
答案 0 :(得分:1)
在xml和
中将Switch
更改为android.support.v7.widget.SwitchCompat
在styles.xml
中创建此样式:
<style name="SwitchTheme">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
并将其添加到您的Switch xml:
android:theme="@style/SwitchTheme"
答案 1 :(得分:0)
设置自定义样式并将其用于xml中的开关:
<style name="MySwitch" parent="@style/Widget.AppCompat.CompoundButton.Switch">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat</item>
您还可以尝试以编程方式使用此功能:
switch1.setTransformationMethod(null);