如何在深色背景上使用材质灯光主题设置Android Spinner的样式?

时间:2015-01-23 16:08:37

标签: android xamarin xamarin.android material-design

我无法弄清楚如何使用v21 Material主题在深色背景抽屉中设置此微调器的样式。我尝试了各种涉及自定义样式的方法,似乎没有什么能比得上这个微调器的外观有所不同。

以下是在Android 5.0.1上运行的应用程序的外观。旋转器,这里有所选项目" 2015年海滩上的代码",位于带有深色背景的抽屉(#DD000000)中,但应用程序的其余部分是浅色主题。箭头显示为黑色 - 几乎无法在设备上看到。我想让它有一个白色箭头。

App Screenshot

这是我的styles.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <style name="app_theme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">#E95624</item>
        <item name="colorPrimaryDark">#BD4000</item>
        <item name="colorAccent">#86d3c5</item>
        <item name="windowActionBar">false</item>
    </style>
</resources>

这是Main.axml文件,这个活动的主要布局,包含DrawerLayout和Spinner:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    a:layout_width="match_parent"
    a:layout_height="match_parent"
    a:orientation="vertical">
    <android.support.v7.widget.Toolbar
        a:id="@+id/main_toolbar"
        a:layout_width="match_parent"
        a:layout_height="wrap_content"
        a:minHeight="?attr/actionBarSize"
        a:background="?attr/colorPrimary"
        a:elevation="2dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    </android.support.v7.widget.Toolbar>
    <android.support.v4.widget.DrawerLayout
        a:id="@+id/drawer_layout"
        a:layout_width="match_parent"
        a:layout_height="match_parent">
        <FrameLayout
            a:id="@+id/content_frame"
            a:layout_width="match_parent"
            a:layout_height="match_parent" />
        <LinearLayout
            a:id="@+id/left_drawer"
            a:orientation="vertical"
            a:layout_width="240dp"
            a:layout_height="match_parent"
            a:layout_gravity="start"
            a:background="#DD000000">
            <Spinner
                a:id="@+id/event_spinner"
                a:layout_width="match_parent"
                a:layout_height="wrap_content"
                a:padding="4dp" />
            <ListView
                a:id="@+id/left_drawer_list"
                a:layout_width="match_parent"
                a:layout_height="wrap_content"
                a:choiceMode="singleChoice"
                a:divider="@android:color/transparent"
                a:dividerHeight="0dp" />
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

如果它是相关的,这里是设置微调器适配器的代码(Xamarin C#):

var adapter = new ArrayAdapter<string>(SupportActionBar.ThemedContext, Resource.Layout.event_selector, events);
  adapter.SetDropDownViewResource(global::Android.Resource.Layout.SimpleSpinnerDropDownItem);

_eventSelector.Adapter = adapter;

这里是我的event_selector.axml(我在拍摄截图后将textColor更改为#fff,不影响箭头颜色):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="8dp"
    android:textSize="16sp"
    android:textColor="#fff" />

我需要对我的.axml或styles.xml文件进行哪些修改才能为此微调器提供白色箭头?提前谢谢!

1 个答案:

答案 0 :(得分:0)

关键是将backgroundTint属性设置为您想要的颜色。

    <Spinner
      a:id="@+id/event_spinner"
      a:layout_width="match_parent"
      a:layout_height="wrap_content"
      a:padding="4dp" 
      a:backgroundTint="#FFFFFF"/>