【发布时间】:2016-03-30 16:43:22
【问题描述】:
我在装有 android 5.1.1 的新设备上测试了我的应用。在我的 SettingsActivity 我有一个开关。我已经阅读了一些帖子并将其更改为android.support.v7.widget.SwitchCompat,但问题仍然如下:在我的旧设备上,开关看起来非常好。您可以为textOn 和textOff 设置两个文本,它非常适合。但自从 api 21 或任何我在这里得到这个小混蛋:
看起来像****。如何为棒棒糖开关等所有设备重新设置样式?
编辑: 上面的问题得到了解答。 少了一件小事:如何改变开关上文字的颜色。(不是左边的标签!!!)
styles.xml
<style name="SwitchTextAppearance" parent="TextAppearance.AppCompat.Widget.Switch">
<item name="android:textSize">12sp</item>
<item name="android:textColor">#3F51B5</item>
</style>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<android.support.v7.widget.SwitchCompat
android:id="@+id/mySwitch"
android:layout_width="match_parent"
android:switchMinWidth="56dp"
android:layout_height="wrap_content"
android:switchTextAppearance="@style/SwitchTextAppearance"
android:thumb="@drawable/thumb"
android:track="@drawable/track"
app:showText="true"
android:textOn="ON"
android:textOff="OFF"
android:text="Toggle Switch"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:color/transparent"
android:button="@null"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
【问题讨论】:
-
你能发布
layout和任何相关的stylexmls 吗? -
我想我明白了。您知道如何更改 switchButton-text 的颜色吗?
-
我更新了答案,为样式添加了文本颜色。
标签: android switch-statement styles switchcompat