我试图奇怪地改变工具栏微调器下拉主题这没有发生.当我点击微调器时,它总是会变暗.我想背景为灰色,文字为黑色.
我没有任何动作栏.我通过工具栏设置一切.
因此我尝试了以下方法:
<?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>
风格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>
更新:
<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>
并将其应用于微调器:
<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" />
使用上面的设置,我可以更改下拉背景颜色但不能在将主题应用到微调器之前,我不能对选择产生涟漪效应吗?
解决方法
只需将以下内容添加到您的Spinner,就像对工具栏一样:
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
所以你的最终Spinner看起来像这样:
<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" />