简体   繁体   English

带白色文本和白色弹出背景的微调框的Android工具栏?

[英]Android Toolbar with Spinner with white text and white popup background?

I've been trying to add a spinner to my toolbar but failed to achieve what I want. 我一直在尝试向工具栏添加微调器,但未能实现我想要的功能。

This is what I have so far. 到目前为止,这就是我所拥有的。

在此处输入图片说明 在此处输入图片说明

As you can see on the screen shots, the Spinner's selected text color is black (I want it to be white) while the popup has a white background with text color black (this is ok). 从屏幕截图中可以看到,微调框的选定文本颜色为黑色(我希望它为白色),而弹出窗口具有白色背景,文本颜色为黑色(可以)。

Here's my code. 这是我的代码。

       <android.support.v7.widget.Toolbar
        android:id="@+id/bottom_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_alignParentBottom="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_date_range_white_24dp" />

            <android.support.v7.widget.AppCompatSpinner
                android:id="@+id/date_range"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:entries="@array/date_range_options"
                android:spinnerMode="dropdown" />

        </LinearLayout>

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

If I change the Toolbar and add app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" like below: 如果我更改工具栏并添加app:theme =“ @ style / ThemeOverlay.AppCompat.Dark.ActionBar”,如下所示:

<android.support.v7.widget.Toolbar
        android:id="@+id/bottom_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_alignParentBottom="true">

I get the white text color of the spinners selected text but the popup background becomes dark with white text color as well. 我得到了微调框选择的文本的白色文本颜色,但是弹出背景也变暗,白色文本颜色也是如此。

I want to have while text color in the selected and with a white popup background with black text. 我想在选中时使用文本颜色,并使用白色弹出背景和黑色文本。

How do I do this? 我该怎么做呢?

You can use a theme to do this 您可以使用主题来执行此操作

<android.support.v7.widget.AppCompatSpinner
                android:id="@+id/date_range"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:entries="@array/date_range_options"
                android:theme="@style/spinnerStyle
                android:spinnerMode="dropdown" />

And then in your styles file 然后在您的样式文件中

<style name="spinnerStyle" parent="AppTheme">
    <item name="colorControlNormal">@color/white_text</item>
    <item name="colorControlActivated">@color/white_text</item>
    <item name="colorControlHighlight">@color/white_text</item>
</style>

Replace @color/white_text with whatever color you want to use. 用您要使用的任何颜色替换@ color / white_text。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM