5

目前我正在使用 IcsSpinner,因为我想要一个跨所有设备的下拉微调器。这就是我想要实现的(显示关闭的微调器并展开):

在此处输入图像描述

但是我不能这样做。我试过这段代码:

<com.actionbarsherlock.internal.widget.IcsSpinner
     android:id="@+id/myspinner"
     style="@style/SpinnerStyle"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:drawSelectorOnTop="true"
     android:minHeight="@dimen/spinner_min_height"
     android:prompt="@string/pick_one" />

风格:

<style name="SpinnerStyle" parent="Sherlock.__Widget.Holo.Spinner">
    <item name="android:popupBackground">@drawable/spinner_selector</item>
    <item name="android:dropDownSelector">@color/white_text</item>
</style>

和可绘制spinner_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item android:state_pressed="true" android:drawable="@color/red" />
   <item android:state_focused="true" android:drawable="@color/red"/>
   <item android:state_selected="true" android:drawable="@color/red"/>
   <item android:drawable="@color/spinner_grey_bg"/>
</selector>

但是输出是这样的:

在此处输入图像描述

我尝试了另一种方法,通过这样做自定义适配器中的视图:

ArrayAdapter<String> myAdapter= new ArrayAdapter<String>(mContext,
                        R.layout.spinner_entry_textview, adapterArray);
mySpinner.setAdapter(myAdapter);

使用spinner_entry.textview.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_spinner_entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/min_height_touch"
android:background="@drawable/spinner_selector"
android:textColor="@drawable/spinner_text_selector"
android:gravity="right|center_vertical"
/>

spinner_text_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="@color/white_text" />
<item android:state_focused="true" android:color="@color/white_text"/>
<item android:state_selected="true" android:color="@color/white_text"/>
<item android:color="@color/red_text"/>
</selector>

但我得到这个输出几乎是我想要的,但它在关闭时也会绘制灰色和红色文本。(箭头指向的第一个元素应该是带有白色文本的深灰色背景)在此处输入图像描述

还尝试将样式应用于默认列表视图,因为微调器似乎有一个内部列表视图但没有做任何事情:

 <style name="AppTheme" parent="Theme.Sherlock.Light">
    <item name="android:listViewStyle">@style/MyListView</item>
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
    <item name="spinnerItemStyle">@style/SpinnerItem</item>
    <item name="spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>

<style name="MyListView" parent="@android:style/Widget.ListView">
    <item name="android:textColor">@drawable/spinner_text_selector</item>
    <item name="android:background">@drawable/spinner_selector</item>
</style>

<style name="SpinnerDropDownItem">
    <item name="android:textColor">@drawable/spinner_text_selector</item>
    <item name="android:background">@drawable/spinner_selector</item>
</style>

<style name="SpinnerStyle" parent="Sherlock.__Widget.Holo.Spinner">
    <item name="android:popupBackground">@drawable/spinner_selector</item>
    <item name="android:dropDownSelector">@color/white_text</item>
</style>

关于如何实现这一目标的任何想法?将不胜感激。

4

0 回答 0