android.support.v7.widget.SwitchCompat无法在API级别22及更低版本中运行

时间:2016-06-21 18:17:02

标签: android user-interface themes android-support-library switchcompat

我有一个简单的android.support.v7.widget.SwitchCompat,如下所示

<android.support.v7.widget.SwitchCompat
    android:id="@id/settings_toggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:text=""
    android:textOff=""
    android:textOn=""
    android:saveEnabled="false"
    android:autoText="false"
    android:theme="@style/ToggleButton"/>

我的风格

<style name="ToggleButton" parent="@style/Theme.AppCompat.Light">
    <item name="colorControlActivated">@color/blue</item>
</style>

以上代码似乎在API级别20或更高版本中正常工作。它不适用于API级别&lt; 20.最低SDK支持是16.无法弄清楚问题。任何投入都表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

我能够找出问题的根本原因。现有的活动风格覆盖了交换机的风格。将相同类型的switch compat应用于活动可以解决问题。

相关问题