I have created a BottomNavigationView with 4 menus. Somehow its not setting the background color to cover the text and icon. See the screenshot, the text and image are still showing the white background
<style name="BottomNavigationView" parent="">
<item name="labelVisibilityMode">labeled</item>
<item name="itemHorizontalTranslationEnabled">false</item>
<item name="itemBackground">#android:color/holo_green_light</item>
<item name="itemTextColor">#drawable/selector_bottom_bar_text</item>
<item name="itemIconTint">#drawable/selector_bottom_bar_icon</item>
<item name="itemTextAppearanceActive">#style/navTextActive</item>
<item name="itemTextAppearanceInactive">#style/navTextInactive</item>
</style>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="#style/BottomNavigationView"
app:menu="#menu/bottom_nav" />
How to fix the text and iconbackground?
How to add a bit of space between the icon and text?
android:background="?android:attr/windowBackground"
app:itemIconTint="#drawable/bg_navigation"
app:itemTextColor="#drawable/bg_navigation"
Then create bg_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:color="hex_color_code" />
<item android:state_checked="true" android:color="hex_color_code" />
</selector>
For Spacing issue, You can check this answer.
I am not sure whether this will work. But, you can try adding this to your Activity.java file and see if it works.
navigationView.setItemIconTintList(null);
navigationView.setBackgroundTintList(null);
Thanks to #Eugen Pechanec. It worked. I was setting the background color in theme. That caused this. After removing the background from the theme it works correctly
Related
This question already has answers here:
Issue: change border color or box stroke for unfocused TextInputLayout in android
(4 answers)
Closed 2 years ago.
I am trying to setting up TextInputLayout unfocused border stroke color. For the same, There are too many questions and their answers and I have tried all of them. Like Created styles and used as theme, Created color selector and applied that, and also applied directly app:boxStrokeColor with color selector. But not luck with any of these available solutions.
Not sure, where do i am doing wrong or something i still missing. I pushed my code to Test project to github for to get better visibility of my whole setup. Here is some sample code for quick review:
activity_main.xml (TextInputLayout inside ConstraintLayout)
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- Tried this as well - app:boxStrokeColor="#color/text_input_box_stroke_color" -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/emailTextInputLayout"
android:hint="Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:theme="#style/TextInputLayoutStyle"
android:layout_marginHorizontal="24dp"
app:layout_constraintTop_toBottomOf="#id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/emailTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#FF00CC</item>
<item name="boxStrokeWidth">2dp</item>
</style>
</resources>
text_input_box_stroke_color.xml (color selector)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/mtrl_textinput_focused_box_stroke_color" android:state_focused="true"/>
<item android:color="#color/mtrl_textinput_hovered_box_stroke_color" android:state_hovered="true"/>
<item android:color="#color/mtrl_textinput_disabled_color" android:state_enabled="false"/>
<item android:color="#color/mtrl_textinput_default_box_stroke_color"/>
</selector>
It would be great help if someone can provide some guideline and suggestion and help me figure out any mistake made by me.
Thanks in advance.
I have tested your code and it works after you do the below changes:
1.First change your res/color/text_input_box_stroke_color.xml like below to see the different states colors. In the below example i have set a Red color for the focused state and a Light Blue color for default-inactive state:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#android:color/holo_red_dark" android:state_focused="true" />
<item android:color="#android:color/holo_green_dark" android:state_hovered="true" />
<item android:color="#color/mtrl_textinput_disabled_color" android:state_enabled="false" />
<item android:color="#android:color/holo_blue_light" />
</selector>
2.Then change your res/values/styles.xml with the boxStrokeColor linking to the above selector like below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box_stroke_color</item>
<item name="boxStrokeWidth">2dp</item>
</style>
</resources>
3.Finally in your TextInputLayout add this style like below:
<com.google.android.material.textfield.TextInputLayout
style="#style/TextInputLayoutStyle"
android:id="#+id/emailTextInputLayout"
Currently your adding the style like: android:theme="#style/TextInputLayoutStyle" instead of style="#style/TextInputLayoutStyle"
Solution for this is next, and this works because I JUST NOW tested it.
Go to your colors.xml inside your res>values folder.
In there you'll have your colorPrimary and other colors you already created before. Scroll to the bottom and add this line:
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#color/colorPrimary</color>
When you do that, you can just change the color there. I defined as #color/colorPrimary but you can use whatever you want. Before applying this line I got this:
And after applying that line this is the result:
Also I applied style="#style/YourStyle" for both TextInputLayout and TextInputEditText
Create a box stroke color for active and inactive state like below:
box_stroke_color
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#2C2C2C" android:state_focused="true"/>
<item android:color="#2C2C2C" android:state_hovered="true"/>
<item android:color="#D7D7D7"/>
</selector>
Make a TextInputLayout style : TextInputLayoutStyle
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/box_stroke_color</item>
<item name="boxStrokeWidth">1dp</item>
</style>
Use in your TextInputLayout
<com.google.android.material.textfield.TextInputLayout
style="#style/TextInputLayoutStyle" >
<com.google.android.material.textfield.TextInputEditText.. />
</com.google.android.material.textfield.TextInputLayout>
I'm placing a TextInputEditText widget onto a white background. When the fragment first loads, the widget does not have focus. The border around the widget is white (or almost white), so it is invisible on a white background. Here is a screenshot of that widget, drawn on a black background for contrast:
As soon as I tap on the widget, the border becomes that of my primary color, which is exactly what I want. Here is a similar screenshot after the widget is activated.
I'm trying to control these colors through a style, and I've tried everything that I can think of, but I cannot figure out how to adjust that color. Here is my style (feel free to laugh at the various attempts):
<style name="MyTextInputLayout" parent="Base.Widget.MaterialComponents.TextInputLayout">
<item name="android:colorBackground">#android:color/black</item>
<item name="android:textColorHint">#color/colorPrimary</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:colorControlActivated">#android:color/black</item>
<item name="android:colorControlNormal">#android:color/black</item>
<item name="android:colorControlHighlight">#android:color/black</item>
<item name="android:backgroundTint">#android:color/black</item>
<item name="android:colorAccent">#android:color/black</item>
</style>
<style name="MyTextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#android:color/black</item>
<item name="android:colorControlActivated">#android:color/black</item>
<item name="android:colorControlNormal">#android:color/black</item>
<item name="android:colorControlHighlight">#android:color/black</item>
<item name="android:backgroundTint">#android:color/black</item>
<item name="android:colorAccent">#android:color/black</item>
</style>
And finally, the xml of the layout in case it is helpful:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/MyTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/reg_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/username"
style="#style/MyTextInputEditText"/>
</com.google.android.material.textfield.TextInputLayout>
How can I change this border color when the widget is not active (i.e. does not have focus)?
I solved this in two main steps:
First problem I had was that the parent style for my TextInputLayout style needed to be changed to Widget.MaterialComponents.TextInputLayout.OutlinedBox.
Once I figured that out, I traced through the Android xml for that style and got to a file called mtrl_box_stroke_color.xml. This is a selector where the three colors for the standard TextInputLayout border are declared. That file looks like this:
So I copied that and created my own file in the res/color folder that I called edit_text_box_border.xml. I modified the three colors to suit my purposes, ultimately coming up with this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<item android:alpha="0.87" android:color="#color/colorPrimary" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="#color/colorPrimary" android:state_enabled="false"/>
<item android:alpha="0.38" android:color="#color/colorPrimary"/>
</selector>
Then, back in my style, I had to get rid of my many color attempts and add an item for boxStrokeColor that pointed to this file. Here are both styles:
<style name="MyTextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:textColorHint">#color/colorPrimary</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="boxStrokeColor">#color/edit_text_box_border</item>
</style>
<style name="MyTextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox.Dense">
<item name="android:textColor">#android:color/black</item>
</style>
Now, when I run the app, I start out with this:
Which then turns into this when I tap on it:
That's what I was going for, so problem solved. Hope this helps someone.
1.
<com.google.android.material.textfield.TextInputLayout
...
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
app:boxStrokeColor = "#android:color/holo_purple"
//border color when in active status
...
2. add the following in colors.xml file
<color name="mtrl_textinput_default_box_stroke_color">#00ff00</color>
//border color when in inactive status
Add
app:boxStrokeColor="#color/black"
app:hintTextColor="#color/black"
to your XML file. I tried all the color options. You can replace the "#color/black" with any color HEX code. Also write app:color and android will show you all the color options, there are many color fields that can be changed, like the error field which we can set to red to indicate the user has entered Invalid Data.
In case you need to change the outline color dynamically (for automatic field validation, for example) you can use the following hack:
Set
app:errorTextColor="#color/colorAccepted"
app:errorIconTint="#color/colorAccepted"
for TextInputLayout in xml.
Then in code:
text_input_layout.errorIconDrawable = null to remove the error icon
and text_input_layout.error = " " to enable the coloring or text_input_layout.error = null to disable it.
This way TextInputLayout takes more space. To resolve this you can customize the errorTextAppearance by defining your own style:
<style name="ErrorTextStyle" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">0sp</item>
</style>
Note:
That's clearly a hack rather than a proper solution.
I use this:
<style name="TextInputLayoutTheme" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">#color/secondaryTextLight</item>
<item name="android:backgroundTint" tools:targetApi="lollipop">#color/colorAccent</item>
<item name="android:textColor">#color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
</style>
and in the xml:
<com.google.android.material.textfield.TextInputEditText
style="#style/TextInputLayoutTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I'm having this issue when I touch an EditText for changing text on Android:
A white frame appears around the red cursor, and I need it to be transparent for showing properly the line of the EditText. How do I change this?
code:
<EditText
android:id="#+id/login_user_name_text"
android:textCursorDrawable="#null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="16sp"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1"
android:hint="#string/email"
android:maxLength="60"
/>
EDIT: I could fix it by replacing:
<item name="android:background">#color/white</item>
for
<item name="android:background">#color/transparent</item>
in styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:background">#color/transparent</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
Sorry for the late,
I think you have <item name="android:popupBackground">#color/white</item> in your style from v21, just remove it, It may solve your problem
Another solution, which works if you are having this problem with an EditText inside a SearchView while using a Toolbar.
In your activity XML add the android:background="?attr/colorPrimary" attribute to Toolbar:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/ToolBarStyle"
android:background="?attr/colorPrimary"
android:elevation="2dp" />
Then, remove <item name="android:background">#color/colorPrimary</item> from your ToolBarStyle in styles.xml.
Hope this helps someone else looking for a solution for this particular case.
better using #android:color/transparent instead of null on the android:textCursorDrawable="#android:color/transparent"
Add the following to your EditText XML instead of null;
android:textCursorDrawable="#drawable/colorcursor"
Then, create a file called colorcursor.xml inside your drawable folder;
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="3dp" />
<solid android:color="#FFFFFF" />
</shape>
Setting android:background to transparent didn't do the trick for me.
In my case I set a theme to the parent viewgroup that defined the background to be a certain color, so it was applied to the EditText as well. Making sure that the background was just set for the parent solved it.
I'm adding a BottomNavigationView to a project, and I would like to have a different text (and icon tint) color for the selected tab (to achieve greying out non-selected tabs effect). Using a different color with android:state_selected="true" in a color selector resource file doesn't seem to work. I also tried having additional item entries with android:state_focused="true" or android:state_enabled="true", no effect unfortunately. Also tried setting the state_selected attribute to false (explicitly) for the default (non-selected) color, with no luck.
Here is how I add the view to my layout:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/silver"
app:itemIconTint="#color/bnv_tab_item_foreground"
app:itemTextColor="#color/bnv_tab_item_foreground"
app:menu="#menu/bottom_nav_bar_menu" />
Here is my color selector (bnv_tab_item_foreground.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#android:color/darker_gray" />
<item android:state_selected="true" android:color="#android:color/holo_blue_dark" />
</selector>
And my menu resource (bottom_nav_bar_menu.xml):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_home"
android:icon="#drawable/ic_local_taxi_black_24dp"
android:title="#string/home" />
<item
android:id="#+id/action_rides"
android:icon="#drawable/ic_local_airport_black_24dp"
android:title="#string/rides"/>
<item
android:id="#+id/action_cafes"
android:icon="#drawable/ic_local_cafe_black_24dp"
android:title="#string/cafes"/>
<item
android:id="#+id/action_hotels"
android:icon="#drawable/ic_local_hotel_black_24dp"
android:title="#string/hotels"/>
</menu>
I would appreciate any help.
While making a selector, always keep the default state at the end, otherwise only default state would be used. You need to reorder the items in your selector as:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#android:color/holo_blue_dark" />
<item android:color="#android:color/darker_gray" />
</selector>
And the state to be used with BottomNavigationBar is state_checked not state_selected.
1. Inside res create folder with name color (like drawable)
2. Right click on color folder. Select
new-> color resource file-> create color.xml file (bnv_tab_item_foreground)
(Figure 1: File Structure)
3. Copy and paste bnv_tab_item_foreground
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
app:itemBackground="#color/appcolor"//diffrent color
app:itemIconTint="#color/bnv_tab_item_foreground" //inside folder 2 diff colors
app:itemTextColor="#color/bnv_tab_item_foreground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/navigation" />
bnv_tab_item_foreground:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/white" />
<item android:color="#android:color/darker_gray" />
</selector>
Figure 1: File Structure:
BottomNavigationView uses colorPrimary from the theme applied for the selected tab and it uses android:textColorSecondary for the inactive tab icon tint.
So you can create a style with the prefered primary color and set it as a theme to your BottomNavigationView in an xml layout file.
styles.xml:
<style name="BottomNavigationTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/active_tab_color</item>
<item name="android:textColorSecondary">#color/inactive_tab_color</item>
</style>
your_layout.xml:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:theme="#style/BottomNavigationTheme"
app:menu="#menu/navigation" />
If you want to change icon and text colors programmatically:
ColorStateList iconColorStates = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
},
new int[]{
Color.parseColor("#123456"),
Color.parseColor("#654321")
});
navigation.setItemIconTintList(iconColorStates);
navigation.setItemTextColor(iconColorStates);
I am using a com.google.android.material.bottomnavigation.BottomNavigationView (not the same as OP's) and I tried a variety of the suggested solutions above, but the only thing that worked was setting app:itemBackground and app:itemIconTint to my selector color worked for me.
<com.google.android.material.bottomnavigation.BottomNavigationView
style="#style/BottomNavigationView"
android:foreground="?attr/selectableItemBackground"
android:theme="#style/BottomNavigationView"
app:itemBackground="#color/tab_color"
app:itemIconTint="#color/tab_color"
app:itemTextColor="#color/bottom_navigation_text_color"
app:labelVisibilityMode="labeled"
app:menu="#menu/bottom_navigation" />
My color/tab_color.xml uses android:state_checked
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/grassSelected" android:state_checked="true" />
<item android:color="#color/grassBackground" />
</selector>
and I am also using a selected state color for color/bottom_navigation_text_color.xml
Not totally relevant here but for full transparency, my BottomNavigationView style is as follows:
<style name="BottomNavigationView" parent="Widget.Design.BottomNavigationView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">#dimen/bottom_navigation_height</item>
<item name="android:layout_gravity">bottom</item>
<item name="android:textSize">#dimen/bottom_navigation_text_size</item>
</style>
It's too late to answer but might be helpful for someone.
I was doing a very silly mistake, I was using a selector file named as bottom_color_nav.xml for Select and unselect color change but still it was not reflecting any color change in BottomNavigationView.
Then I realize, I was returning false in onNavigationItemSelected method. It will work fine if you'll return true in this method.
In order to set textColor, BottomNavigationView has two style properties you can set directly from the xml:
itemTextAppearanceActive
itemTextAppearanceInactive
In your layout.xml file:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bnvMainNavigation"
style="#style/NavigationView"/>
In your styles.xml file:
<style name="NavigationView" parent="Widget.MaterialComponents.BottomNavigationView">
<item name="itemTextAppearanceActive">#style/ActiveText</item>
<item name="itemTextAppearanceInactive">#style/InactiveText</item>
</style>
<style name="ActiveText">
<item name="android:textColor">#color/colorPrimary</item>
</style>
<style name="InactiveText">
<item name="android:textColor">#color/colorBaseBlack</item>
</style>
Try using android:state_enabled rather than android:state_selected for the selector item attributes.
This will work:
setItemBackgroundResource(android.R.color.holo_red_light)
Instead of creating selector,
Best way to create a style.
<style name="AppTheme.BottomBar">
<item name="colorPrimary">#color/colorAccent</item>
</style>
and to change the text size, selected or non selected.
<dimen name="design_bottom_navigation_text_size" tools:override="true">11sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen>
Enjoy Android!
As the folder structure has changed, the tab_color.xml belongs to res > drawable now which can handle selectors. From there on the accepted solution works.
This is a pretty specific question. I have a spinner on an ActionBar that is added in the onCreate() method. I have been able to style the text white, but I can't get the underline and the triangle/arrow at the bottom right to appear as white. Here is my styling:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:textColor">#FFFFFF</item>
</style>
I can't find a style item/property that makes the underline and triangle white. Does one exists?
Here's an example. I have highlighted in red the triangle and underline that I want to make white.
A bit late answer, but better than never :)
You should create a new 9 patch drawable and set it as a background to android:actionDropDownStyle.
here is an example:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle"parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/custom_spinner_dropdown</item>
</style>
You can't set a color to almost every native component, as their backgrounds are (in most cases) 9-patch pngs.
The actionDropDownStyle can not used to change the style of spinner you added on actionbar; its for one of the actionbar mode ActionBar.NAVIGATION_MODE_LIST;
As for your problem, you can define a selector for your spinner in the layout file,just like this:
enter code here
<Spinner
android:dropDownWidth="200dp"
android:background="#drawable/actionbar_spinner"
android:id="#+id/action_spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dp" />
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="#drawable/spinner_ab_disabled" />
<item android:state_pressed="true"
android:drawable="#drawable/spinner_ab_pressed" />
<item android:state_pressed="false" android:state_focused="true"
android:drawable="#drawable/spinner_ab_focused" />
<item android:drawable="#drawable/spinner_ab_default" />
</selector>
Try this : android:background="#null"