2015-01-18 9 views
1

У меня есть SwitchCompat в панели действий (v7.Toolbar) моей активности. Я хочу, чтобы это была colorStructure при выключенном и colorAccent, когда включен. Он отлично работает на pre-Lollipop, но на Lollipop активированный переключатель рисуется в цвете, который я нигде не определял. Он выглядит как «material_deep_teal_200». Вот мое только определение стиля:Цвет SwitchCompat на Lollipop

<?xml version="1.0" encoding="utf-8"?> 
 
<resources> 
 
\t <style name="Theme.Default" parent="Theme.AppCompat.Light.NoActionBar"> 
 
\t \t <item name="colorPrimary">@color/colorPrimary</item> 
 
\t \t <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
 
\t \t <item name="colorAccent">@color/colorAccent</item> 
 
\t \t <!--<item name="android:windowNoTitle">true</item>--> 
 
\t \t <item name="windowActionBar">false</item> 
 
\t \t <item name="colorSwitchThumbNormal">@color/colorStructure</item> 
 
\t \t <item name="colorControlNormal">@color/colorPrimary</item> 
 
\t \t <item name="colorControlActivated">@color/colorAccent</item> 
 
\t \t <item name="colorControlHighlight">@color/colorAccent</item> 
 
\t \t <!--<item name="selectBarStyle">@style/DefaultSelectBar</item>--> 
 
\t </style> 
 
</resources>

И это начало своей деятельности XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:tools="http://schemas.android.com/tools" 
 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="match_parent" 
 
       android:orientation="vertical" 
 
\t > 
 

 
\t <android.support.v7.widget.Toolbar 
 
\t \t android:id="@+id/toolbar" 
 
\t \t android:layout_height="wrap_content" 
 
\t \t android:layout_width="match_parent" 
 
\t \t app:theme="@style/Widget.AppCompat.Toolbar" 
 
\t \t app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
 
\t \t android:background="@color/colorPrimary" 
 
\t \t android:paddingRight="@dimen/abc_dropdownitem_text_padding_right"> 
 

 
\t \t <FrameLayout 
 
\t \t \t android:layout_width="match_parent" 
 
\t \t \t android:layout_height="wrap_content" 
 
\t \t \t android:paddingRight="@dimen/abc_action_bar_icon_vertical_padding_material"> 
 

 
\t \t \t <ImageButton 
 
\t \t \t \t android:layout_width="wrap_content" 
 
\t \t \t \t android:layout_height="wrap_content" 
 
\t \t \t \t android:id="@+id/helpButton" 
 
\t \t \t \t android:src="@drawable/ic_help_large" 
 
\t \t \t \t android:background="#00000000" 
 
\t \t \t \t android:layout_gravity="center"/> 
 

 
\t \t \t <android.support.v7.widget.SwitchCompat 
 
\t \t \t \t android:layout_width="wrap_content" 
 
\t \t \t \t android:layout_height="wrap_content" 
 
\t \t \t \t android:id="@+id/master_switch" 
 
\t \t \t \t android:clickable="true" 
 
\t \t \t \t android:checked="true" 
 
\t \t \t \t android:gravity="center" 
 
\t \t \t \t android:layout_gravity="right" 
 
\t \t \t \t /> 
 

 
\t \t </FrameLayout> 
 

 
\t \t </android.support.v7.widget.Toolbar>

Так что мне нужно изменить, чтобы сделать переключатель имеет одинаковые цвета на KitKat и Lollipop?

Благодаря

+0

у вас есть свой стиль в значениях-20 значений-v21 папок? – Abdellah

ответ

0

На самом деле код, представленный выше, работает отлично - и на леденец. Я, должно быть, допустил ошибку во время проверки после очистки проблемного кода.

Первоначально проблема была в том, что у меня также была конфигурация в значениях-v21. Я предполагаю, что была опечатка или что-то в этом роде, которое потерялось, когда я упростил все это в XML-файл по умолчанию.

Короче говоря, представленный код работает, и я предполагаю, что наличие конфигураций в значениях-v21 также не вызовет проблемы.