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.
Related
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.
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
So I've basically looked into every resource I saw online on how to change the blue underline in the tabs, but all of the advice has not worked in my case.
I tried actionbarsherlock, appcombat, holo from Action Bar Generator but all the coloring did was color the top action bar, not the tab underline. And yes the files did compile and did not have any errors, but for some reason, it seemed like the underline would never be changed even through the generator.
I am confused on how to change the default blue underline on the tabs, and I would SO EXTREMELY appreciate it if there was a working custom style xml that you would share.
After going to Changing ActionBar tabs underline color programmatically result is still same :/
Screen shot after trying from other page: http://i.stack.imgur.com/EOUbu.png
Anyone able to help me out?
I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set colorAccent in your theme and that will change the highlight color on your ActionBar. Like so:
<item name="colorAccent">#color/highlightcolor</item>
Here it is in context:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/darkgrey</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/highlightcolor</item>
</style>
You need to define a custom theme for that, and then check the states to change the colour of the line. See if this answer helps you
Not sure if you are still pursuing this, but can you show what you did with Action Bar Generator? What Style entries did you add (in XML) and which drawables did you add?
I just went through the same process and it worked well with Action Bar Generator; just required a few lines added to the styles.xml, a new xml file in drawables folder, and then about 5 new image drawables into each of the resolution size folders (drawable-hdpi, etc).
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.
In my Android application I need to have a black action bar and my content has a white background. The problem is that whenever I set the actionbar with a black background, all my dropdown spinners and textviews have a white background, and I can't see them together with my white content background. If I set the actionbar to white, the dropdown spinners and textviews have a black background and I can see them properly. I tryed customizing the style from the dropdown spinner with android:dropDownSpinnerStyle But i didn't succeed. How can I solve this?
Edit:
I just solved this issue regarding the Dropdown using the following:
<item name="android:dropDownSpinnerStyle">#style/customDropDownStyle</item>
<style name="customDropDownStyle" parent="#android:style/Widget.Holo.Light.Spinner">
</style>
But I still have this issue regarding an EditText, in which I can't see it's background. I just can't find the attribute I should work with in order to solve the issue.
It was much easier to keep the style of the APP in a way that the dropbox/textfields would be visible, but changing only the style of the Actionbar like that:
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<item name="android:actionOverflowButtonStyle">#android:style/Widget.Holo.ActionButton.Overflow</item>
<item name="android:actionBarTabStyle">#style/customActionBarTabStyle</item>