Android 微调器下拉箭头

Android 微调器下拉箭头,android,android-layout,spinner,Android,Android Layout,Spinner,我正在尝试获得一个自定义微调器,例如: 但我只能得到这个: 如你所见,我遇到了几个问题 虽然我添加了一个自定义箭头,但仍然可以看到原始箭头 我的自定义箭头显示在每一行 如何调整自定义箭头的尺寸和布局位置 如何生成带下划线的行 这是我的代码: onCreateView(): 编辑 我删除了ImageView,并添加了从资源创建的第二个Spinner: ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResour

我正在尝试获得一个自定义微调器,例如:

但我只能得到这个:

如你所见,我遇到了几个问题

  • 虽然我添加了一个自定义箭头,但仍然可以看到原始箭头
  • 我的自定义箭头显示在每一行
  • 如何调整自定义箭头的尺寸和布局位置
  • 如何生成带下划线的行
  • 这是我的代码:

    onCreateView()

    编辑

    我删除了
    ImageView
    ,并添加了从资源创建的第二个
    Spinner

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            getActivity(),
            R.array.date,
            R.layout.spinner_layout);
    spinnerDate.setAdapter(adapter);
    
    Spinner spinnerTime = (Spinner) rootView.findViewById(R.id.spinnerTime);
    ArrayAdapter<CharSequence> adapterTime = ArrayAdapter.createFromResource(
            getActivity(),
            R.array.ore,
            R.layout.spinner_layout);
    spinnerTime.setAdapter(adapterTime);
    
    但是没有结果!我仍然看到:

    编辑2

    我已将
    style.xml
    更改为:

    这就是我得到的:

    现在,我甚至没有替换下拉箭头图标,而是有了第二个图标,holo复选框(它工作正常,当我选择一个项目时会被选中),但是,我怎么才能只得到我想要的呢

    manifest.xml


    您必须将
    Imageview
    删除到自定义布局
    row\u spinner.xml
    中。在这种情况下,您不需要在自定义布局中创建箭头,因为如果您这样做,它将在每一行中创建,就像您遇到的一样。要执行您向我们展示的相同操作,必须将
    微调器
    样式更改为
    style.xml

    例如:

    <resources>
    
        <style name="SpinnerTheme" parent="android:Widget.Spinner">
            <item name="android:background">@drawable/spinner_background_holo_light</item>
            <item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerTheme.DropDown">
            <item name="android:spinnerMode">dropdown</item>
        </style>
    
        <!-- Changes the spinner drop down item radio button style -->
        <style name="DropDownItemSpinnerTheme" parent="android:Widget.DropDownItem.Spinner">
            <item name="android:checkMark">@drawable/btn_radio_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme" parent="android:Widget.ListView">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme.White" parent="android:Widget.ListView.White">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerItemTheme" 
                parent="android:TextAppearance.Widget.TextView.SpinnerItem">
            <item name="android:textColor">#000000</item>
        </style>
    
    </resources>
    

    您可以使用自己的下拉图像

    
    //向下箭头替换图像
    
    @CrisBenois,看一看:完成。但我仍然看到了那支古老的箭。添加这些样式和我的箭头图标后,如何应用“SpinnerTheme”?您不需要应用,因为主题应用于作为此部件的父级Spinner的每个组件
    。您是否从自定义布局中删除了
    ImageView
    ?正如我在您的代码中所看到的,您只是在使用
    喷丝头主题,而不是其他主题。我发布的代码只是一个示例,所以您几乎需要更改所有内容。不管怎样,我在我的应用程序中测试了一些代码,它工作得非常好。看看我的编辑,记住这只是一个例子,然后你必须调整它。对不起,伙计,耽搁了。我不知道你的项目是怎么回事。我用我所知道的所有方法来做旋转器得到
    样式
    ,但不起作用。但是,我尝试将
    android:background=“@drawable/spinner\u item\u drawable”
    添加到
    details\u fragment\u three.xml
    中的每个微调器代码中,效果非常好。因此,您不需要在
    样式中执行任何操作。检查我的编辑答案,看看这部分代码现在看起来如何。
    
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            getActivity(),
            R.array.date,
            R.layout.spinner_layout);
    spinnerDate.setAdapter(adapter);
    
    Spinner spinnerTime = (Spinner) rootView.findViewById(R.id.spinnerTime);
    ArrayAdapter<CharSequence> adapterTime = ArrayAdapter.createFromResource(
            getActivity(),
            R.array.ore,
            R.layout.spinner_layout);
    spinnerTime.setAdapter(adapterTime);
    
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:padding="8dp"
        android:singleLine="true"
        android:layout_height="wrap_content" android:layout_width="match_parent"/>
    
    <style name="AppTheme" parent="@style/_AppTheme"/>
    <!-- Base application theme. -->
    <style name="_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:dropDownSpinnerStyle">@style/SpinnerTheme   </item>
    
        <item name="android:windowActionBarOverlay">false</item>
        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
    </style>
    
    ....
    .... 
    ....
    
    <!--Spinner styles 2-->
    <style name="SpinnerTheme" parent="android:Widget.Spinner">
        <item name="android:background">@drawable/apptheme_spinner_background_holo_light</item>
        <item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
    </style>
    
    <style name="SpinnerTheme.DropDown">
        <item name="android:spinnerMode">dropdown</item>
    </style>
    
    <!-- Changes the spinner drop down item radio button style -->
    <style name="DropDownItemSpinnerTheme" parent="android:Widget.DropDownItem.Spinner">
        <item name="android:checkMark">@drawable/apptheme_btn_radio_holo_light</item>
    </style>
    
    <style name="ListViewSpinnerTheme" parent="android:Widget.ListView">
        <item name="android:listSelector">@drawable/apptheme_list_selector_holo_light</item>
    </style>
    
    <style name="ListViewSpinnerTheme.White" parent="android:Widget.ListView.White">
        <item name="android:listSelector">@drawable/apptheme_list_selector_holo_light</item>
    </style>
    
    <style name="SpinnerItemTheme"
        parent="android:TextAppearance.Widget.TextView.SpinnerItem">
        <item name="android:textColor">#000000</item>
    </style>
    
    <resources>
    
        <style name="SpinnerTheme" parent="android:Widget.Spinner">
            <item name="android:background">@drawable/spinner_background_holo_light</item>
            <item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerTheme.DropDown">
            <item name="android:spinnerMode">dropdown</item>
        </style>
    
        <!-- Changes the spinner drop down item radio button style -->
        <style name="DropDownItemSpinnerTheme" parent="android:Widget.DropDownItem.Spinner">
            <item name="android:checkMark">@drawable/btn_radio_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme" parent="android:Widget.ListView">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme.White" parent="android:Widget.ListView.White">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerItemTheme" 
                parent="android:TextAppearance.Widget.TextView.SpinnerItem">
            <item name="android:textColor">#000000</item>
        </style>
    
    </resources>
    
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item>
    
            <layer-list>
    
                <item>
                    <shape>
                        <gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
    
                        <stroke android:width="1dp" android:color="#504a4b" />
    
                        <corners android:radius="5dp" />
    
                        <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
                    </shape>
                </item>
    
                <item>
    
                    <bitmap android:gravity="bottom|right" android:src="@android:drawable/arrow_up_float" />
    
                </item>
    
            </layer-list>
    
        </item>
    
    </selector>
    
    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
            <item name="android:spinnerStyle">@style/SpinnerTheme</item>
        </style>
    
        <style name="SpinnerTheme" parent="android:Widget.Spinner">
            <item name="android:background">@drawable/selector_spinner</item>
        </style>
    
    </resources>
    
    <Spinner
        android:id="@+id/spinnerDate"
        android:layout_marginLeft="-8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/spinner_item_drawable"/> 
    
            <item>
    
                <layer-list>
    
                    <item>
                        <color android:color="@android:color/white" />
                    </item>
    
                    <item>
                        <bitmap android:gravity="center_vertical|right" android:src="@drawable/down_arrow" /> // down_arrow replace your image
                    </item>
    
                </layer-list>
    
            </item>
    
        </selector>