Reputation: 498
I searched a lot and couldn't solve my problem. I want to customize my app's action bar.
I'm calling the actiong this way:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
/*
* menu.add(int groupId, int itemId, int order, CharSequence title);
*/
MenuItem menu0 = menu.add(0, 0, 0, "Action Item 0");
{
menu0.setIcon(R.drawable.ic_launcher);
menu0.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
return true;
}
And my style.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:textColor">#CCCCCC</item>
</style>
However the textcolor remains in default (# FFF), have tried everything and do not know where I'm going wrong, I appreciate any help. Thank you!
Upvotes: 3
Views: 7715
Reputation: 498
Thank you guys, I did what I want by this tutorial: http://shreymalhotra.me/blog/tutorial/android/android-create-custom-themes-for-your-apps/
Added this on onCreate():
final ActionBar bar = getActionBar();
And to change the title color my style.xml look like this:
<style name="Theme.MyAppTheme" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#ccc</item>
</style>
Obs: Im not sure, but I think that my first style will work with that line on the oncreate() method.
Upvotes: 3
Reputation: 24012
Try this:
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:textColor">#CCCCCC</item>
<item name="textColor">#CCCCCC</item>
</style>
Sometimes because of the API you use, removing android: works
also try to define the color in color.xml
and use this way:
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:textColor">@color/mColor</item>
<item name="textColor">@color/mColor</item>
</style>
EDIT:
<style name="MyActionBar"parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextColor">@style/MyTheme.ActionBar.TitleTextColor</item>
</style>
<style name="MyActionBar.TitleTextColor" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/mColor</item>
</style>
Upvotes: 4