android - Change the style of ActionBar -
im working on actionbar , i'm trying change style, want background white , text color blue, im doing following style.xml:
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light"> <!-- customize theme here. --> <item name="colorprimary">@color/action_bar</item> <item name="coloraccent">@color/top_bar</item> <item name="colorprimarydark">@color/cyan_500</item> <item name="android:windowcontentoverlay">@null</item> <item name="android:actionbarstyle">@style/myactionbar</item> </style> <style name="myactionbar" parent="@style/widget.appcompat.light.actionbar"> <item name="android:actionbarsize">20dp</item> <item name="android:background">@color/white</item> <item name="android:titletextstyle">@style/mytitletextbarstyle</item> </style> <style name="mytitletextbarstyle" parent="@style/textappearance.appcompat.widget.actionbar.title"> <item name="android:textcolor">@color/colorrb</item> </style> </resources>
and nothing happening, api 15 22. have managed change background code doing this:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_reasonlocation); android.support.v7.app.actionbar mab = getsupportactionbar(); mab.settitle(getstring(r.string.reasonandlocation)); mcd.setcolor(getresources().getcolor(r.color.white)); mab.setbackgrounddrawable(mcd); ... }
if know how can solve this, either style.xml or code, appreciate.
you can define color of actionbar (and other stuff) by creating custom style:
simply edit the res/values/styles.xmlfile of android project.
for example this:
<resources> <style name="mycustomtheme" parent="@android:style/theme.holo.light"> <item name="android:actionbarstyle">@style/myactionbartheme</item> </style> <style name="myactionbartheme" parent="@android:style/widget.holo.light.actionbar"> <item name="android:background">any_hex_color_code</item> </style> </resources>
then set "mycustomtheme" theme of activity contains actionbar.
you can set color actionbar this:
actionbar actionbar = getactionbar(); actionbar.setbackgrounddrawable(new colordrawable(color.red)); // set desired color
Comments
Post a Comment