I know this question must be asked before, but I don't know where can I find the solution since I don't know what is the name.
I want to change the color to red. How can I do to achieve this ?
Thanks a lot !
A style on Android contains a number of different attributes. This can control background color, text color, font styling, etc.
The Theme.AppCompat.Light.DarkActionBar style contains several attributes for an overall light theme with a dark colored action bar.
If the background color you want to use needs white text and icons on top of it, you reference this as the parent and just change the background color.
<item name="android:background">#ff0000</item>
If your background color would look better with black (or dark) text, you could set the parent to Theme.AppCompat.Light.
If you want to change the color of the application bar (and the application's primary color – the application bar inherits it), just change your colorPrimary attribute. Like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/yourColorResource</item>
</style>
Instead of #color/yourColorResource, you can directly use a color's hexcode or Android's pre-defined resources such as #android:color/holo_red_dark
For the status bar's color, you can use similarly use the colorPrimaryDark attribute. You can read more about this here.
Related
I'm trying to set my Action Bar color to transparent, so it will have the same color as the background and will also blend in with the gradient background.
I tried doing something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#android:color/transparent</item>
</style>
When I run my app, it launches, loads the screen for one second (all rendered correctly, action bar is transparent), then crashes to the following exception:
java.lang.IllegalArgumentException: background can not be translucent: #0
Tracing to no relevant class of my project.
If I set the parameter to a solid color, everything works fine.
Can you help me with the problem? I couldn't find any solution.
Thanks.
Your app isn't crashing as a result of the ActionBar background being transparent, but as a result of your colorPrimary being transparent, in combination with using the MediaRouter lib.
MediaRouterThemeHelper.getControllerColor and MediaRouterThemeHelper.getButtonTextColor both make calls to ColorUtils.calculateContrast, which is where your IllegalArgumentException is coming from.
ColorUtils.calculateContrast needs a fully opaque color in order to correctly calculate contrast, just based on the formula being used and MediaRouterThemeHelper uses colorPrimary to determine how to theme the MediaRouter controller and button text color.
It looks like you're using a NoActionBar style, so I'm assuming you're using a Toolbar and just setting the background to be your colorPrimary. Instead you could just use #android:color/transparent directly and change your colorPrimary to something opaque.
I want to change the colour of homeAsUpIndicator but this item in theme only accepts a drawable. Is there any way of having a different colour arrow other than providing my own custom icon?
<item name="android:homeAsUpIndicator"..
You should take the drawable from the SDK and use transparency or color to get the effect you want. For example http://s13.postimg.org/cd16ya3hf/ic_home_back.png
I need to change the underline color of the ActionBar tabs programmatically. I've checked around SO and found nothing; I've looked at this question, but none of the answers helped.
I know how to change the color in styles.xml like so:
<style name="ActionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#color/red</item>
</style>
I know how to change the background color, but I need to change the color of the white line below Tab 1.
I need to change this color while the app is running, using Java code. Is there any way to do this?
there are two ways you can do this
you can get action bar instance and call actionbar.setBackgroundDrawable with this you can change background color of the action bar
else define two different custom themes in app and change the theme programatically.
I want to change the background and text colors of the pop up menu that appears when the user presses the overflow icon.
If I use Theme.Holo or Theme.Holo.Light it works, but I'm using Theme.Holo.Light.DarkActionBar and it never works. I'm starting to assume that it's an Android bug.
I'm testing on a Nexus 4 with 4.4.2 but it also doesn't work on an emulator with API 19.
After trying a lot of potential solutions that I came across here in StackOverflow, here is what I'm doing:
<style name="Theme.MyApp" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/ActionBarWidget</item>
</style>
<style name="AndroidPitActionBarWidget" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#android:style/Widget.Holo.Light.PopupMenu</item>
<item name="android:dropDownListViewStyle">#android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>
That works but it changes the styling of the SearchView, which is another pain to change.
So I'm not considering this a solution.
What I want is to just change the background/text of the popup to the Light version, which is light background with black text.
I also tried setting those two attributes in the main theme instead of using the actionBarWidgetTheme.
It's really frustrating to waste hours on this kind of problems.
I also tried using Action Bar Style Generator to make the background white, but then the text is white and I can't change it to black.
Thanks very much in advance.
If you set the background color of that panel using the theme you get in the Action Bar Style Generator, you can try adding the android:textColor attribute of the drop down ListView.
If that does not work, you can alternately set the string color in code during your onCreateOptionsMenu method as detailed on this SO thread
I was changing the background of the Actionbar in my App and to make text readable again I have to change the color of the text. I was successful with title/subtitle and the tab-texts, but I am struggling with the text of the action-items - they stay white no matter what I tried . Anyone has a hint on how to do that?
Also the overflow-icon is white which does not look too good on the wooden background - is that an extremely good reason to use the stuff below? I am not really sure what's the reason to not do it, but as I do not have a big device-test-park I better want to be sure ;-)
<!-- the following can be used to style the overflow menu button
only do this if you have an *extremely* good reason to!! -->
<!--<style name="MyOverflowButton" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">#drawable/ic_menu_view</item>
<item name="android:background">#drawable/action_button_background</item>
</style>-->
I also struggled with this, but the solution to changing action item text color was:
<style name="My.Theme" parent="Theme.Sherlock.Light">
<item name="android:actionMenuTextColor">#android:color/white</item>
</style>
The key here was to use this attribute in the general theme, not in the actionbar style.
Try starting with android:theme="#style/Theme.Sherlock.Light" in your Manifest and then changing your styles. The light theme features dark action items. Or just look through the light theme to find out how to change them.