android 3.0+ action bar keep background when styling - android

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.

Related

ActionBar Theme is ignored

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.

Title do not appear on android action bar

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>

Color "splitActionBarWhenNarrow" Bottom Action Bar

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>

How to change action bar background when using the Support Library?

I tried example code (https://developer.android.com/training/basics/actionbar/styling.html) on 'Customize the Background'.
but I want to know how this works. -> '#drawable/actionbar_background'
It seems to add 'actionbar_background.png' file to somewhere res folder but I don't know where.
So I changed source like this.
<!-- Action Bar styles -->
<style
name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF6600</item>
<!-- Support library compatibility -->
<item name="background">#FF6600</item>
</style>
but this part
<item name="background">#FF6600</item>
doesn't work.
I don't know what type is appropriate.
Please Use this in style.xml in res>>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.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="#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">#4cb9f6</item>
</style>
In my case I also couldn't change the background using the XML style file, so I just changed the color inside the "onCreate" of my activity.
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(MY_COLOR)));
Maybe this isn't the best practice, but it is functional.

Set custom style and action bar

I'm developing an app that needs to work with action bar and tab bar, my first issue was to set up a custom text style for the label on the tab bar, now I want to use the action bar, but I'm having trouble with custom style and action bar. I made a custom style so:
styles.xml
<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. -->
</style>
<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">10sp</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Now I read here that I can add an action bar to a custom style, so i tried to do so:
styles.xml
<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. -->
</style>
<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
<item name="android:actionBarStyle">#style/Widget.ActionBar</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">10sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="Widget.ActionBar" parent="android:Widget.Holo.Light.ActionBar">
<item name="android:displayOptions">showHome|useLogo|showCustom</item>
<item name="android:customNavigationLayout">#layout/custom</item>
</style>
</resources>
If you look at my xml code you can see that I add the Widget.ActionBar style to display an action bar on my activity. When I try to run my app I can see the custom style for the tab host, but I can't see the action bar.
I need action bar to put there a the share button.
Can you help me?
Have you try this?
Here it given to make actionbarserlock.

Categories

Resources