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.
Related
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>
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>
I am the using the ActionBarSherlock. I have the displayOption "homeAsUp" in my style.xml file. Now this shows a black arrow next to the title of the Activity. Since my theme is White on a blue blackground, i want to change the color of the black arrow, or maybe use a whole new icon resource in its place. How can i do this ?
Kind Regards.
Further to Eric's answer - I wasted a lot of time getting this right.
Remember that these items must go in the parent application theme, inheriting from Theme.Sherlock or similar.
<!-- CUSTOM APP THEME -->
<style name="AppTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="android:homeAsUpIndicator">#drawable/action_bar_ic_ab_back_holo_dark</item>
<item name="homeAsUpIndicator">#drawable/action_bar_ic_ab_back_holo_dark</item>
</style>
Do not put them in the custom Action Bar theme inheriting from Widget.Sherlock.ActionBar.
<!-- ACTION BAR THEME -->
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
<item name="android:icon">#drawable/action_bar_logo</item>
<item name="icon">#drawable/action_bar_logo</item>
<item name="android:displayOptions">showHome</item>
<item name="displayOptions">showHome</item>
</style>
Be careful when you style ActionBarSherlock !
Here is an extract from the web site (ActionBarSherlock Theming):
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation. Since both theming APIs are exactly the same you need only reference your customizations twice rather than having to implement them twice.
So in your case you MUST define two item:
<item name="android:homeAsUpIndicator">#drawable/icon</item>
and
<item name="homeAsUpIndicator">#drawable/icon</item>
Then you are sure that ALL your users will have the same L&F
I need to change the style of my SearchView in my ActionBar. In particular I need to change the text hint color and the SearchView icons if possible. How can I accomplish this in XML (is it even possible in XML)?
If this isn't possible, how can I easily recreate similar behavior with a custom view? The close/expand behavior of the SearchView is particularly useful for me.
Have you tried something like this (With ActionBarSherlock):
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));
It works fine for me.
It looks like you may need to supply a custom layout for your search action. I haven't been able to find any documents that talk about modifying the default SearchView. But this does allow the close/expand behavior.
http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
Related questions:
Honeycomb - customize SearchView inside the action bar
set numeric input type to SearchView in ActionBar
You need to create a new theme and use it in manifest file.
<style name="Theme.Test" parent="#style/Theme.AppCompat.Light">
<item name="searchViewAutoCompleteTextView">#style/Theme.Test.SearchField</item>
</style>
<!-- Search edit text -->
<style name="Theme.Test.SearchField" parent="#style/Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">#color/white</item>
<item name="android:textColorHint">#color/white</item>
</style>
It worked fine for me.
The right answer is to overload the action bar widget style with your own custom style. For holo light with dark action bar, put this in your own styles file such as res/values/styles_mytheme.xml:
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/Theme.MyTheme.Widget</item>
<!-- your other custom styles -->
</style>
<style name="Theme.MyTheme.Widget" parent="#android:style/Theme.Holo">
<item name="android:textColorHint">#android:color/white</item>
<!-- your other custom widget styles -->
</style>
Make sure your application is using theme custom theme as described in enter link description here
Ok, this is driving me bonkers. To skin my app, I set the following in my theme:
<item name="android:textColor">#FFFFFF</item>
All the text in the app turns white, unless I manually override it in the layout xmls. Great, yay, easy peasy. EXCEPT that the text in my menu options for context menus (off of lists and such) have also decided to become white.
This is not so great, since it is hard to read white on white. I have tried a variety of solutions, including searching for how to change the text color of a context menu (no dice)and creating a textAppearance item in my theme. The last solution didn't change all the textfields in my app, which was frustrating.
So, any suggestions? Hopefully my dilema is clear.
In your styles.xml try overriding the textViewStyle instead of just ALL textColor attributes:
<style name="Theme.Blundell.Light" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/background_light</item>
<item name="android:textViewStyle">#style/Widget.TextView.Black</item>
</style>
<style name="Widget.TextView.Black" parent="#android:style/Widget.TextView">
<item name="android:textColor">#000000</item>
</style>
You could even take it one further and just override the color for a certain view, like buttons:
<style name="Widget.Holo.Button" parent="#android:style/Widget.Holo.Button">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="Theme.Blundell" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:colorBackground">#android:color/transparent</item>
<item name="android:buttonStyle">#style/Widget.Holo.Button</item>
</style>
If your inspired to do any more theming check out the Android source it's the best place to realise what you can and can't do!:
https://github.com/android/platform_frameworks_base/tree/master/core/res/res/values
Use this:
parent="Theme.AppCompat.Light.DarkActionBar"