user interface - How to use colors from android standard themes? -


i want create custom controls , stylize them according current theme. how can access colors , drawables in standard system themes?

if you're referring retrieving colors colorprimary or colorprimarydark theme dynamically, let's theme looks like

 <style name="apptheme.orangetheme" parent="theme.appcompat.light">     <item name="colorprimary">@color/orange</item>     <item name="colorprimarydark">@color/orangedark</item>     <item name="coloraccent">@color/orangeaccent</item> </style> 

you can access primarycolor styledattributes using method

public static int getprimarycolorfromselectedtheme(context context) {     int[] attrs = {r.attr.colorprimary, r.attr.colorprimarydark};     typedarray ta = context.gettheme().obtainstyledattributes(attrs);     int primarycolor = ta.getcolor(0, color.black); //1 index primarycolordark     //default value primarycolor set black if primarycolor not found     ta.recycle();     return primarycolor; } 

similarly, can access coloraccent well, adding attributes.

about drawables, don't quite understand mean accessing drawables in standard system themes. can access android drawables using

contextcompat.getdrawable(context, android.r.drawable.[drawable name]);  

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -