I'm trying to make the background colour of my ActionBar a colour corresponding to the code. For some reason my app crashes when it reaches this line of code.
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3f9845")));
When I remove it the error goes (ActionBar background is set to black by default). I've tried rearranging the line to be above and below
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_register1);
but still no luck.
This is the theme I'm using if it has any relevance
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> </style>
Thanks in advance for any help
If you are using AppCompat, you need to call getSupportActionBar() instead.
If you want to change the color by style with the recent versions of AppCompat, you just need to set the "colorPrimary" attribute in your theme to the color you want.
you can set it in the style:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_action_bar_color</item>
</style>
Related
I have received a design spec. in which the status bar icons' color is to be changed completely. I know I can change the status bar color in theme, however that is not my question. I want to override the icon color/icons themselves as shown in the image attached.
I searched a bit but could not find a way to do it.
I am aware that as a last resort, I can change the existing status bar icon tintcolor the following attribute in my app theme.
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
You can change it by setting the android:statusBarColor or android:colorPrimaryDark attribute of the style you're using for your app in styles.xml.
(android:statusBarColor inherits the value of android:colorPrimaryDark by default)
For example (since we're using an AppCompat theme here, the android namespace is omitted):
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#color/your_custom_color</item>
</style>
On API level 21+ you can also use the Window.setStatusBarColor() method from code.
<item name="colorPrimaryDark">#color/your_color</item>
will only be visible in Lollipop and greater than Lollipop(API) devices. P.S. you need to have Theme.AppCompat as your base/main theme
I've having an issue with my actionBar that I've implemented.The screenshots below that I've provided will highlight the problem that I'm facing.Currently when I start my MainActivity,I've a navigation drawer and an actionBar.But the problem I'm facing is that there a split-second loading of the actionbar where it's in its original white color as shown below.
And then it immediately proceeds on changing its color as I've set as shown belown.
My issue is,how do I prevent the ActionBar for being "white" for a quick split second before it changes color?How do I let the actionBar be immediately green the moment the Activity starts?Thank you for the help :)
If you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<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>
And, set "MyTheme" as theme for application / activity. It will not show that split second problem.
Are you setting the color in your activity?
Perhaps you can try using Styles instead?
I am trying to change the blue background of a focussed/pressed menuitem in the overflow menu.
I'm talking about this:
I think I've overwritten every possible attribute from the Themeand Theme.Holo in Themes.xml and went to each style in Styles.xml but couldn't change the blue background.
EDIT
i figured out that the style i should override is android:dropDownListViewStyle
but it didn't work at all.
but then i changed the theme from Theme.Holo.Light.DarkActionBar to Theme.Holo.Light and guess what? it worked!!
so, can anyone shed some light on this?? how can i change the color on a theme with DarkActionBar??
ok, i found a solution for my problem: link to a post in the ActionBarSherlock google group
i've overseen this entry: android:actionBarWidgetTheme in the Theme.Holo.Light.DarkActionBar theme.
now all i had to do is define a theme that overrides Theme.Holo with one style in it: <item name="android:dropDownListViewStyle">#style/myDropDownListView</item> and point to this theme instead.
<!-- theme referenced by actionBarWidgetTehme style -->
<style name="Theme.DropDown.Dark" parent="android:style/Theme.Holo">
<item name="android:dropDownListViewStyle">#style/myDropDownListView</item>
</style>
<!-- my main theme -->
<style name="DarkActionBarRedActionMode" parent="android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/Theme.DropDown.Dark</item>
</style>
declare a selector drawable, and put it as background of listview item.
refer to drawable resource
I've got a custom theme that inherits from Theme.Holo.Light.DarkActionBar and I'm trying to change the theme's tabWidget style so it to look like if the theme was Theme.Holo Dark.
I've tried this in my theme with no result
<style name="AppTheme" parent="android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:tabWidgetStyle">#android:style/Widget.Holo.TabWidget</item>
...
</style>
The only thing I can appreciate is there is a small change in the blue bar of the tab.
Any idea how to get it? Thanks!
Try also the items "android:tabStripLeft" and "android:tabStripRight".
I am working on an app which will be full-screen, but will utilize some of the functionalities of the ActionBar. With the Ice Cream Sandwhich release, I see that I get a blue line divider/separator as part of the ActionBar. Normally, it would be good for consistency, but in my case I need to remove the divider.
How can I remove or style the divider of the ActionBar in ICS?
Tried setting a custom theme with "android:style/Widget.Holo.ActionBar" as parent.
However, settings such as the one below has no effect
<item name="android:divider">#FFFFFF</item>
The graphic asset containing the blue bottom line is the background of the action bar's container view and is set to #android:drawable/ab_transparent_dark_holo when using the default Holo Dark theme.
To remove this line, you'll need to create a custom style for your action bar (based on Widget.Holo.ActionBar or Widget.Holo.Light.ActionBar (or the .Solid variants) and set the android:background to something that doesn't include the bottom border:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#drawable/your_background_here</item>
</style>
Note: Holo Dark/Light action bars have solid and transparent styles; this blue line appears by default for the transparent style. Holo Dark action bars are transparent by default and Holo Light action bars are solid by default.
Here is a simple way to remove the divider, works from API 07 using the actionbarcompat from the support library:
#Override
public void onCreate(Bundle savedInstanceState) {
//...
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.whatever_you_want));
//...
}
Changing the activity theme to Theme.Holo.Light.DarkActionBar removes the blue line.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:textColor">#android:color/white</item>
</style>
If you still want a black background you may want to change android:windowBackground and/or android:textColor
add this <item name="android:windowContentOverlay">#null</item> to your app theme.