Action Bar disappears after applying background - android

I applied a gradient background to my ActionBar. I can see it in the preview on Eclipse but when I run the app on my phone, the action bar vanishes completely. Why is this happening?
styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="android:Theme.Holo.Light">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
</resources>

try use to:
Drawable d=getResources().getDrawable(R.drawable.background_image_name);
getActionBar().setBackgroundDrawable(d);
and see this question link

Related

Why isn't the action bar text color changing?

I am on android lollipop and using the following style as my theme MyNavigationDrawerTheme
in styles v14
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light">
<item name="actionMenuTextColor">#color/white</item>
</style>
in material drawer theme.xml (mostly irrelevant to this issue)
<style name="MaterialNavigationDrawerTheme.Light" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="drawerType">#integer/DRAWERTYPE_ACCOUNTS</item>
<item name="drawerColor">#fafafa</item>
</style>
I understand that the theme Theme.AppCompat.Light.NoActionBar has black text for the action bar but why isn't it changing when I include the line
<item name="actionMenuTextColor">#color/white</item>
I have been trying to fix this for almost two days now tried so many things (eg here) but nothing works
Any idea
you could try this in styles.xml:
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light">
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextAppearance">#style/TextAppearance.ActionMenu
</item>
</style>
<style name="TextAppearance.ActionMenu">
<item name="android:textColor">#color/white</item>
</style>
ps:
yeah ,sometimes it won't works only by android:actionMenuTextColor ,such as Galaxy S4
just add attr android:actionMenuTextAppearance
In case you are using Toolbar, this is how you do it -
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">#android:color/holo_red_dark</item>
<item name="textColorPrimary">#android:color/holo_red_dark</item>
<!-- Customize your theme here. -->
</style>
Should work like a charm :)

Android actionbar background around title

Android Studio 1.1.0. SDK 22 Installed&Compiled, SDK 17 Target (I suppose it's not relevant, because issue occurs also on preview in IDE).
I started playing with Holo theme action bar styling and ran into an issue, involving background color. This is my styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#ff0d3200</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
And this is output. I want app title's background color to be the same as action bar's. As I've said, it's the same on the preview, so I don't think it's because my phone(SDK17) or emulator. Overflow button behaves the same way, there just isn't any in this case.
I tried setting android:titleTextStyle in BarTheme to this style:
<style name="TitleTheme" parent="android:TextAppearance.Holo">
<item name="android:background">#443322</item>
</style>
But it didn't change a thing. What do I do to overcome this?
try ,
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">value</item>
<item name="android:titleTextStyle">#style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">value</item>
</style>
Due to David's input I solved my problem myself. I had to set windowBackground, instead of background in AppTheme. I'm not sure what is the exact difference, but it works properly. Remember not to change attribute in your BarTheme, because it won't work with windowBackground. Therefore correct styles.xml file is:
<resources>
<color name="bcColor">#ff0d3200</color>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#color/bcColor</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
Note that color has to be defined as resource in this case and cannot be hardcoded. The clean way to do this is create colors.xml in values folder and define all colors there.

Action bar with custom background not shown

I am trying to change the background of the action bar via xml, but the action bar is not shown anymore at all.
This is the style that I am using, declared in styles.xml:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/DiaryActionBar</item>
<item name="android:actionBarStyle">#style/DiaryActionBar</item>
</style>
<style name="DiaryActionBar"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="background">#color/action_bar_bg</item>
<item name="android:background">#color/action_bar_bg</item>
</style>
I have set both android:background and background for compatibility. This is the only styles.xml file in my app. What am I doing wrong?
In my style with custom actionbar background, i have this:
<style name="Theme.Malaka" parent="#style/Theme.AppCompat">
<style name="Malaka.ActionBar" parent="#style/Widget.AppCompat.ActionBar">
And that works just fine. Items of the styles are the same as yours. Please note that the parent of Malaka.ActionBar is not Theme... but Widget...
For changing background and actionBarStyle from android styling.You can do like this..
<style name="AppBaseTheme" parent="#android:style/Theme.Black">
<item name="android:actionBarStyle">#style/Theme.DeviceDefault.NoActionBar</item>
</style>
<style name="DiaryActionBar" parent="#android:style/Theme.Black">
<item name="android:background">#color/action_bar_bg</item>
</style>

Action bar title/icon not using theme color

I'm doing a custom style for the action bar in my application. I've changed action bar to the blue background and white text that I wanted, and that works fine. However the area around the app's title and icon, which I think is the transparent region, is showing the general theme background instead of the action bar background. So instead of the transparency 'falling through' to the action bar, it's falling through to the base background.
Here's an image that displays the problem (I've changed the theme background to red to highlight the issue).
How can I resolve this?
Here's my styles.xml file:
<resources>
<style name="MyTheme" parent="#style/Theme.AppCompat">
<item name="android:background">#FF0000</item>
<item name="android:textColor">#color/cp_text</item>
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:actionButtonStyle">#style/CustomActionBarButton</item>
<item name="android:actionModeBackground">#color/cp_titlebar_background</item>
</style>
<style name="CustomActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/cp_titlebar_background</item>
<item name="android:textColor">#color/cp_text</item>
<item name="android:titleTextStyle">#style/CPTitleTextStyle</item>
</style>
<style name="CPTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/cp_text</item>
<item name="android:background">#color/cp_titlebar_background</item>
</style>
<style name="CustomActionBarButton" parent="#android:style/Widget.ActionButton">
<item name="android:background">#color/cp_titlebar_background</item>
</style>
</resources>
By setting <item name="android:background">#FF0000</item> on your base theme, all views and widgets will use this value for their background.
If you are wanting to set the background colour for activities in your theme, then use the android:windowBackground attribute instead of background.

Actionbar sherlock light theme

Now I am working on a android app using actionbar sherlock and fragment.I used the following theme.
<style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.ForceOverflow">
<item name="android:actionDropDownStyle">#style/MyDropDownNav</item>
<item name="actionDropDownStyle">#style/MyDropDownNav</item>
</style>
And I got the following Output.
But I want use the light theme so I changed the parent as
parent="Theme.Sherlock.Light.ForceOverflow"
Then I got the following output
The light theme is missing the blue underline. How can i make that blue underline?...Please help me friends.
You have to create you own theme in order to do that:
<resources>
<style name="MyTheme" 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>
As the Background you can then put a modified 9 patch Image with a blue underline. Look at your Android Sdk > API 13+ there should be the original Actionbar bavkground drawables. Just modify them and set it as background. Don't forget to set this Theme as your App theme later on.
Edit:
Here are some 9 Patch images from Jake Whartons Action Bar Sherlock(what a coincidence that he formated my post earlier...:) ):
Create your own style for action bar and override background property:
<style name="MyActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/bg_action_bar</item>
<item name="background">#drawable/bg_action_bar</item>
</style>
Use this style for your action bar in theme:
<style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
</style>
Take a look onto res\drawable-hdpi\abs__ab_transparent_light_holo.9.png drawable inside ActionBarSherlock sources how to create 9-patch drawable with color strip line at the bottom.

Categories

Resources