Various colorControlActivated styles in Android
This is the theme of my application:
<style name="BaseTheme" parent="Theme.AppCompat.Light"> ... <item name="colorControlActivated">@color/default_orange</item> ... </style> ... <style name="Switch" parent="Material.Widget.Switch"> <item name="colorControlActivated">@color/default_green</item> </style> And if I use the Switch style:
<com.rey.material.widget.Switch style="@style/Switch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false"/> colorControlActivated used it inside BaseTheme (orange) instead of Switch (green).
Why is this happening? Can I have different colorControlActivated for different types? Thanks.
The main problem is that the colorControlActivated attribute in the action subject has a preference for this attribute in any custom style that you define and apply to certain views.
The solution (and this solution overrides the attribute for all elements of the same activity in the same way) to create a new topic and apply this theme to your activity in the manifest. This theme can inherit from your main theme and redefine only those attributes that you need.
Topics:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- items--> <item name="colorControlActivated">@android:color/white</item> <!-- items--> </style> <style name="lightAppTheme" parent="AppTheme" > <item name="colorControlActivated">@color/colorPrimary</item> </style> manifesto:
<application android:name=".application.appname" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/title_activity_main" android:theme="@style/lightAppTheme" android:screenOrientation="portrait"></activity> </application> I hope this helps anyone who comes to this, as it took me several hours to get it to work.
For different elements of the same activity to use different colorControlActivated attributes, go to this.