I want to change the title color of actionbar to white. I have declared on styles:
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">#style/ProjActionBar</item>
<item name="android:actionBarTabTextStyle">#style/ProjActionBar.TitleTextStyle</item>
</style>
<!-- ActionBar Style -->
<style name="ProjActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/b</item>
<item name="android:backgroundStacked">#color/k1</item>
<!-- This is when tabs are splitted into a second line -->
</style>
<style name="ProjActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/w</item>
<item name="android:textSize">13sp</item>
</style>
As you can see I have a "actionBarTabTextStyle" declared with the attribute "textColor" to #color/w declared in my colors.xml as:
<color name="w">#FFFFFFFF</color>
What happend? why the actionbar title does not change textColor?
My project is targeted to min SDK 11 sdkVersion 17 (Honeycomb 3.0+)
The problem is that you have not actually changed the title text style. You have changed the style of the tab text. To change the title text style, you want to set android:titleTextStyle and optionally android:subtitleTextStyle on your ProjActionBar style.
So, your ProjActionBar becomes this:
<style name="ProjActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/b</item>
<item name="android:backgroundStacked">#color/k1</item>
<item name="android:titleTextStyle">#style/ProjActionBar.TitleTextStyle</item>
</style>
Please note that this assumes you are using the native ActionBar components (as indicated by the fact that you are inheriting from #android:style/Widget.Holo.Light.ActionBar). If you want backwards compatibility, you will have to inherit your style from Widget.AppCompat.Light.ActionBar and use textStyle instead of android:textStyle.
Related
This is strange.
I'm trying to change color of ActionBar using themes.
Here's my code for styles.xml in values:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:actionBarStyle">#style/TheActionBarTheme</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="TheActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#1f1f2f</item>
</style>
</resources>
And for styles.xml in values-14:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">#style/TheActionBarTheme</item>
</style>
<style name="TheActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#1f1f2f</item>
</style>
</resources>
I use requestWindowFeature(Window.FEATURE_ACTION_BAR); in MainActivity
But the color of ActionBar doesn't change - it is standart. Where did I screw up?
I got your problem , I am sharing a xml style code to you check that.
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#693EB4</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
In this code sample I have made a new style for action bar in style.xml, in this colorPrimary is small top bar(StatusBar) color and colorPrimary dark is the color of ActionBar, so you need to change this color.
And the parent value is the type of action bar theme you want.
I am trying to style my actionbar with background color. I have also given label in the android manifest file which shows up in the action bar. But when i try to change background color using Style.xml , it changes the background color but do not show label.
Below is the Style xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="background">#color/actionbarcolor</item>
</style>
could you please let me know , what change i should make so that it shows label name also after applying background color.
I have applied theme "AppTheme" at application level in manifest file .
Try to add this
<style>
<item name="android:actionBarTabTextStyle">#style/AwesomeTabTextStyle</item>
</style>
<style name="AwesomeTabTextStyle" parent="#android:style/Widget.ActionBar.TabText">
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#color/actionbar_text_color</item>
</style>
I have an MainActivity extends ActionBarActivity , I want to color my action bar I used a custom style , the problem that the custom styles I'm using requires Api 11 At least I tried using:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0099cc")));
But the Bottom ActionBar is Not Colored
This Is My Style.xml :
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
If you want to color your split action bar u will have to use android:backgroundSplit. following code will help you.
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#9933CC</item>
<item name="android:backgroundSplit">#9933CC</item>
<item name="android:titleTextStyle">#style/myTheme.ActionBar.Text</item>
</style>
<style name="myTheme.ActionBar.Text" parent="#android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
<item name="android:typeface">monospace</item>
<item name="android:textStyle">bold</item>
</style>
I know the question seems simple, but not anything like chei here before. So there you go:
In my android application using the Support Library with AppCompat v7, added an ActionBar. Everything works perfectly, except that when the application runs on android 2.3, the background of the ActionBar is dark, and when the squeegee android 4.0.2 ActionBar this background turns gray.
Below is how to define my #style
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
how can I solve this?
This will not work for you on min target as 2.3.3 in case your min target is API level 11 you can change the background color
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
I would like to add my observation (using min sdk 8, target sdk 19) for the future readers on this issue.
If you want to set just the background color of the action bar across different android versions, its easier to do it in code.
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable( getResources().getDrawable(R.color.your_desired_color));
This overrides the default background across versions and set your desired color.
Note: I had seen on various post and tried to set the background color as follows:
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(R.color.your_desired_color);
actionBar.setBackgroundDrawable(colorDrawable);
but it did not work, reason unknown to me for the time being.so I successfully tried the code mentioned above.
if you want to set the background color of the action bar (along with other attributes) not in code, you can use style and theme. I had done the styling as follows.
inside res/values/style.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
inside res/values-v11 and res/values-v14
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
Note:
As I had to have similar look for the action bar across android versions, I had copy-pasted the code in res/values-v11 and res/values-v14 from res/values. But to my surprise,I did not get the desired result. Reason? We need to add the "android" namespace before the tags for android v11 and later. So I changed actionBarStyle to android:actionBarStyle and background to android:background. That brought me the desired result.
I'm developing an App for Android 3.0+ and I want to personalize the action bar by removing the title, which I can accomplish, my problem is that I also lose the background on the action bar, I would just like to remove the title and keep the remaining style. Here's what I'm currently using:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/ActionBarNoTitle</item>
</style>
<style name="ActionBarNoTitle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>
I'd prefer not to change the Activity code to accomplish this.
Which theme are you using? That is probably defined in values-v11 or values-v14. If Theme.Holo.Light you have to change the actionBarStyle's parent style to Widget.Holo.Light.ActionBar.Solid.
<style name="ActionBarNoTitle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
Did you try this,
define this in your theme.xml file,
<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
define this in your style.xml file,
<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="android:subtitleTextStyle">#style/NoTitleText</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
Let me know if this works.