Spinner Theme is dark in Android
Asked Answered
W

1

12

I am trying to change the toolbar spinner dropdown theme strangely this is not happening. It is coming up always dark when I click on the spinner. I would like to have the background grey and text black.

I don't have any actionbar. I am setting everything through toolbar.

Hence I tried the following:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <RelativeLayout
        android:id="@+id/relativeLayoutID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="left|center"
            android:text="@string/register_title"
            android:textColor="@color/whiteText"
            android:textSize="@dimen/text_size_medium" />

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="80dp"
            android:spinnerMode="dropdown"
            android:visibility="gone" />

    </RelativeLayout>

</android.support.v7.widget.Toolbar>

Style xml:

 <resources>

<style name="Theme.default" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="md_widget_color">@color/numbertext</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:windowContentOverlay">@drawable/toolbar_dropshadow</item>
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:editTextColor">@android:color/background_dark</item>
    <item name="android:textColor">@android:color/background_dark</item>
    <item name="colorControlNormal">@android:color/background_dark</item>
    <item name="colorControlActivated">@color/orangeText</item>
    <item name="colorControlHighlight">@color/orangeText</item>
    <item name="android:statusBarColor">@color/colorPrimary</item>

</style>

<style name="Widget.MyApp.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
    <item name="android:background">?android:selectableItemBackground</item>
    <item name="android:dropDownSelector">?android:selectableItemBackground</item>
    <item name="android:divider">@color/blackText</item>
    <item name="android:overlapAnchor">true</item>
</style></resources>

Update:

Added the following theme:

<style name="MyDarkToolbarStyle" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
        <item name="background">?android:selectableItemBackground</item>
        <item name="android:popupBackground">@color/layoutbackground</item>
        <item name="android:dropDownSelector">?android:selectableItemBackground</item>
        <item name="android:divider">@color/blackText</item>
        <item name="android:overlapAnchor">true</item>
    </style>

And applied it to the spinner:

<Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="80dp"
style="@style/MyDarkToolbarStyle"
            android:spinnerMode="dropdown"
            android:visibility="gone" />

With above settings I could change the dropdown background color but not I am not able to get ripple effect on selection this used to happen before applying the theme to the spinner?

Week answered 19/7, 2015 at 9:12 Comment(7)
Is that dark theme in local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" intentional?Issuant
@SaschaKolberg: If I change to light then my drop down arrow and navigation drawer horizontal lines become dark. How do I change that to white?Week
Sorry, I don't understand that last comment.Issuant
The three horizontal line (Navigation Drawer ICON) is in black color?Week
Ok, now I get it (I think). You use local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" to just get the white foreground color, right? Have you tried using a cusomized "@style/Theme.AppCompat.Light" for local:popupTheme instead of a ThemeOverlay?Issuant
@SaschaKolberg: Nope not tried How do I do that where should I put them?Week
@SaschaKolberg : I tried the following: Please check my question I have updated it there. I am getting perfect color but the ripple effect when selecting an item from dropdown is not happening in 5.0 and more. what could be wrong? Ripple effect is there if don't apply the theme.Week
T
23

Just add the following to your Spinner the same way you did for your Toolbar:

local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

So your final Spinner will look like this:

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="80dp"
    android:spinnerMode="dropdown"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:visibility="gone" />
Trevortrevorr answered 4/4, 2016 at 1:21 Comment(4)
Great. Thanks. I have already tried the same way. It is working fine. Do you think you can help me out with this theme issue: #36348159Week
No, sorry I haven't worked with those features yet. Please mark this answer has accepted if it worked for you so it can help others.Trevortrevorr
@SanjanaNair please accept the answer if it worked for you. Don't just ask and then leave, but reward the people that take the effort to help you.Muskrat
In my case I am using "app" instead of "local"Medin

© 2022 - 2024 — McMap. All rights reserved.