Android: SwitchCompat, padding and color issues

I am using android.support.v7.widget.SwitchCompat and I am having the following problems.

  • My style, which includes colorControlActivated, doesn't apply.
  • Replacing a proxy server using the Android and Res-Auto namespaces has no effect
  • How to set maximum text for all caps

My code

styles.xml

Notice that I tried without parent and Theme.AppCompat.Light.NoActionBar

<style name="ToggleSwitchStyle" parent="Theme.AppCompat"> <item name="colorControlActivated">@color/emerald</item> </style> 

My SwitchCompat defined in XML layout

 <android.support.v7.widget.SwitchCompat android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:padding="5dp" android:textOff="@string/no" android:textOn="@string/yes" app:showText="true" android:switchPadding="5dp" app:switchPadding="10dp" app:theme="@style/ToggleSwitchStyle" android:theme="@style/ToggleSwitchStyle" android:textAllCaps="true" app:thumbTextPadding="5dp" > 

So in the text above, AllCaps does not make the text on the thumb with all the caps.

Passage filling does not affect

A theme using the Res-Auto or Android namespace does not affect the active color.

However, I can change the active color by changing the color accent to my material theme.

  <!-- Application theme. --> <style name="MaterialDesign" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/yellow</item> </style> 
+6
source share
1 answer

Make sure your Styles.xml is in the v21 values ​​folder. I had similar problems with switchcompat for changing colors.

It worked for me. Storing styles.xml in the v21 and ColorAccent value folders for changing the color of the switch.

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="colortoggle"> <item name="colorAccent">@color/continue_button</item> </style> </resources> 

For the thumb: TextAppearance and its associated setTypeface () methods control the font and style of the label text, while switchTextAppearance and its associated seSwitchTypeface () methods control the thumb.

0
source

Source: https://habr.com/ru/post/989962/


All Articles