How to change programmatically the primary color in Android L -
is there way change programmatically primary colors. in code depending screen/state of app.
currently can set colors in theme (static) :
<item name="android:colorprimary">@color/primary_color</item> <item name="android:colorprimarydark">@color/dark_color</item> <item name="android:colorbackground">@android:color/white</item> <item name="android:coloraccent">@color/primary_color</item> <item name="android:colorcontrolhighlight">@color/primary_color</item>
thanks
you can, of course, implement custom subclasses of view have methods setting colors.
you can define multiple themes various color schemes.
views theme information context when created. change styles applied theme have recreate view hierarchy context uses right theme.
one way that, create new contextthemewrapper , layoutinflator uses theme wrapper, remove old version of layout , re-inflate layout.
roughly:
contextthemewrapper themewrapper = new contextthemewrapper(this, r.style.appthemewithcolorscheme2); layoutinflater layoutinflater = layoutinflater.from(themewrapper); viewcontainer.removeallviews(); layoutinflater.inflate(r.layout.my_layout, viewcontainer, true );
if using action bar, may bit more tricky, because action bar created once per activity.
Comments
Post a Comment