Why does custom action bar background style hide text? - android

i am tuning my action bar, the problem is that when i set the background property in my child theme then action bar text will disappear:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#android:color/holo_blue_dark</item>
<item name="background">#android:color/holo_blue_dark</item>
</style>
If i override the background then the remaining properties should come from the parent theme by my logic, this includes that the text is still visible.
In order to get the text back i need to write the following:
<item name="android:displayOptions">showHome|useLogo|showTitle</item>
Why do i need to write that? Why does setting the background remove the text from the parent theme? Thanks in advance for the clarifications.

The problem is that you are inheriting from an incorrect style. Instead of inheriting from Widget.Holo.Light.ActionBar make your actionBarStyle be a descendant of one of AppCompat styles, e.g. Widget.AppCompat.Light.ActionBar.Solid.
<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
<!-- override attributes here -->
</style>

Related

Android SearchView icon disappears when SearchView style is overridden

I have a SearchView in the main content area of my activity.
I need to override the SearchView style in my style.xml files (so I can remove the SearchView's underline - as shown here).
However, when I override the SearchView style, its searchIcon just disappears from the UI:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="searchViewStyle">#style/MySearchView</item>
<item name="android:searchViewStyle">#style/MySearchView</item>
</style>
<style name="MySearchView" parent="Widget.AppCompat.Light.SearchView">
<!-- nothing entered here yet! -->
</style>
I know I can specify my own drawable for the searchIcon, but I would like to use the default one.
So how do I specify MySearchView style without losing the default searchIcon?
Update #1
I don't know if this is normal, but I also have a problem where if I override the Button style using this approach, then my buttons lose all their padding and therefore become too small:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">#style/MyButton</item>
<item name="android:buttonStyle">#style/MyButton</item>
</style>
<style name="MyButton" parent="android:style/Widget.Button">
<item name="android:textColor">#color/white</item>
<item name="android:background">#color/red</item>
</style>
It seems the issue here was using a framework class with a style meant for a support class. The correct SearchView class to use with an AppCompat theme is android.support.v7.widget.SearchView, rather than android.widget.SearchView.
A framework View isn't going to be looking for attributes defined for a support View, so those attributes' settings will just be lost. Since no valid resources would be found during the SearchView's construction, null would be set as the image for each icon's ImageButton, which would explain why multiple icons seemed to have disappeared with this style.

Set static colors in app. Colors cannot change in various device OS

I want to set colors specially in my application.
For a example if i add a ProgressBar in my application and set a color with android:indeterminateTint="#BDBDBD" (Gray). This can not be change.
It doesn't matter the device or theme the progress bar color should be #BDBDBD.
I think you are looking for a global declarable style which can be placed in style.xml. Add a android:progressBarStylein your parent style that is used by all of the activities.
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:progressBarStyle">#style/CustomProgressBar</item>
</style>
Make the progress bar customizations here,
<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">#drawable/custom_progress_bar_horizontal</item>
<item name="android:minHeight">10dip</item>
<item name="android:maxHeight">20dip</item>
</style>
Now your progress bar style should be applied in all of the activities.
Check the official demos code here,
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml

android - how to remove ActionBarDivider in Holo theme

I have an Activity with a dark ActionBar. I need to remove its vertical dividers since my icons already have "built-in" dividers.
What I've tried goes below
Activity style:
<style name="sMain" parent="#android:style/Theme.Holo">
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
MyActionBar:
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:actionBarDivider">#null</item>
</style>
This doesn't have any effect. Any ideas what I'm doing wrong?
You need to set the android:actionBarStyle attribute as part of the activity theme, not as part of the action bar style.
So I believe this should work:
<style name="sMain" parent="#android:style/Theme.Holo">
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarDivider">#null</item>
</style>
How to tell where attributes belong? I used to struggle with this too (usually solved by trial-and-error) until I discovered the use of the android.R.styleable class! Have a look here: https://developer.android.com/reference/android/R.styleable.html
If you do a search in the page for actionBarStyle you will see it shows up as Theme_actionBarStyle, meaning it is part of the Theme style (remember there is no technical difference between a theme and a style). If you do a search on ActionBar_ you will be able to iterate through all of the attributes that can be set as part of an ActionBar style.

ActionBarSherlock Change Text Color of Overflow Action Items

I'm working on an android app and I am using ActionBarSherlock for compatibility. Everything works great so far, except the fact that I want to change the text color of the overflow menu items.
Here's the way they currently look:
Now, the reason for this is that I am usign Holo.Light.DarkActionBar as the Base theme since that way the icons are white, the text is white on the ActionBar's Title and SubTitle, and some other things.
To my knowledge, and per this question, I should be able to simply change the following:
<!-- For Values -->
<style name="Theme.Laprensa_compat_holo_light_dark_action_bar" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="spinnerItemStyle">#style/SpinnerItemStyle</item>
<!-- For Values-v14 -->
<style name="Theme.Laprensa_compat_holo_light_dark_action_bar" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:spinnerItemStyle">#style/SpinnerItemStyle</item>
And the SpinnerItemStyle is:
<style name="SpinnerItemStyle" parent="Widget.Sherlock.TextView.SpinnerItem">
<item name="android:textColor">#android:color/black</item>
</style>
Now, that doesn't seem to be working, so I added
<item name="spinnerItemStyle">#style/SpinnerItemStyle</item>
To the children theme too:
<style name="ActionBar.Solid.Laprensa_compat_holo_light_dark_action_bar" parent="#style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
It's still a no-go.
The Answer I referenced stated that i should make sure that I am using the correct adapter layout, but in reality, I am not inflating any code myself manually, it's the regular onCreateOptionsMenu implementation.
Any ideas on what could I change to make the text black? And you should know that changing actionMenuTextColor is for items hosted on the action bar itself, and doesn't change the overflow menu items
EDIT As per Matthias' answer, I tried the following style:
<style name="TextAppearance.Styled.Widget.PopupMenu.Large" parent="TextAppearance.Sherlock.Widget.PopupMenu.Large">
<item name="android:textColor">#android:color/black</item>
</style>
and used it on the main theme:
<style name="Theme.Laprensa_compat_holo_light_dark_action_bar" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="textAppearanceLargePopupMenu">#style/TextAppearance.Styled.Widget.PopupMenu.Large</item>
</style>
But the text is still non-visible.
<style name="AppTheme" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:textAppearanceLargePopupMenu">
#style/TextAppearance.Styled.Widget.PopupMenu.Large</item>
</style>
<style name="TextAppearance.Styled.Widget.PopupMenu.Large"
parent="TextAppearance.Sherlock.Widget.PopupMenu.Large">
<item name="android:textColor">?attr/textColorPrimaryInverse</item>
</style>

Action bar custom view

I want to declare a custom view, BUT I also want the home logo with up icon to appear on the left with its default functionality. How can I achieve to use both?
Best way is to use XML styles:
<style name="Theme.Main" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/Widget.ActionBar</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>
Then simply set this theme as either the application theme or activity them in AndroidManifest.xml

Categories

Resources