Android: SwitchCompat, padding and colour issues -


i using android.support.v7.widget.switchcompat , encountering following problems

  • my style includes colorcontrolactivated not apply
  • switch padding using android namespace , res-auto has no effect
  • how set thumb text caps

my code

styles.xml

note tried no parent , 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 above textallcaps not make text on thumb caps.

switch padding has no effect

the theme using res-auto or android namespace has no effect on active colour.

however can change active colour changing colour accent on 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> 

make sure styles.xml in values-v21 folder. had similar issues switchcompat changing color .

this worked me. keeping styles.xml in values-v21 folder , coloraccent change color of switch.

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

for thumb issue: textappearance , related settypeface() methods control typeface , style of label text, whereas switchtextappearance , related seswitchtypeface() methods control of thumb.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -