android.R.attr.colorPrimary gives me the wrong colors all the time -


i'm trying give buttons colors current themes attributes: android.r.attr.colorprimary or r.attr.colorprimary should return yellow, gives me blue color time instead! have set theme in manifest.

setting example backgroundcolor of toolbar android:background="?attr/colorprimary" gives correct color, not if set code.

this how i'm trying set color of button:

    typedvalue typedvalue = new typedvalue();     app.getappcontex().gettheme().resolveattribute(android.r.attr.colorprimary, typedvalue, true);     buttoncolor = typedvalue.data;       addbutton.settext("save");     addbutton.getbackground().setcolorfilter(buttoncolor, porterduff.mode.multiply); 

this "yellow" theme

  <style name="apptheme_yellow" parent="theme.appcompat.light.noactionbar">     <item name="colorprimary">@color/primaryyellow</item>     <item name="colorprimarydark">@color/primary_darkyellow</item>     <item name="coloraccent">@color/accentyellow</item>     <item name="android:textcolorprimary">@color/primary_textyellow</item>     <item name="android:textcolorsecondary">@color/secondary_textyellow</item>     <item name="android:icon">@color/iconsyellow</item>     <item name="actionoverflowbuttonstyle">@style/overflowstyle</item>     <item name="popupmenustyle">@style/popupmenustyle</item> 

the colors behind "yellow" theme:

<color name="primaryyellow">#ffc107</color> <color name="primary_darkyellow">#ffa000</color> <color name="primary_lightyellow">#ffecb3</color> <color name="accentyellow">#607d8b</color> <color name="primary_textyellow">#212121</color> <color name="secondary_textyellow">#727272</color> <color name="iconsyellow">#212121</color> <color name="divideryellow">#b6b6b6</color> 

i found problem in global application context using. app.getappcontex().gettheme().resolveattribute(android.r.attr.colorprimary, typedvalue, true);

so 1 must use the getactivity() or context of activity ui wigdets inilitized in:

getactivity().gettheme().resolveattribute(android.r.attr.colorprimary, typedvalue, true);  

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -