更改微调框下拉图标 [英] Change Spinner dropdown icon
问题描述
我发现可以更改微调框下拉菜单图标的解决方案,其中包括:
The solutions I found to change the spinner dropdown icon where all:
1.创建自定义可绘制对象
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/vector_drawable_ic_dropdown_black" android:state_focused="true" android:state_pressed="false" />
<item android:drawable="@drawable/vector_drawable_ic_dropdown_black" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@drawable/vector_drawable_ic_dropdown_black" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@drawable/vector_drawable_ic_dropdown_black" />
</selector>
2.将可绘制对象设置为微调器背景:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@drawable/custom_spinner_icon"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="@color/textcolorprimary" />
结果是:
如您所见,这是不可接受的解决方案,因为图标需要右对齐而不要拉伸.
As you can see this is not an acceptable solution since the icon needs to be right aligned and not stretched.
我该怎么做才能使图标不能拉伸并正确对齐?
What can i do to make the icon not stretch and align it right?
编辑
由于没有可行的解决方案,我想我必须指定我的问题. 这是使用标准主题的Spinner的外观:
Since there are no working solutions yet i guess i have to specify my question. This is how my Spinner looks using the standard theme:
<Spinner
android:id="@+id/products_download_spinner_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="@color/textcolorprimary"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar" />
我想要的所有东西(我猜真的不多)都在改变箭头.我不希望该箭头显示在右下角,我希望该箭头垂直居中显示在右侧:
And everything i want (it is really not much i guess) is changing the arrow. i dont want that arrow in the right bottom corner to be displayed, i want this arrow to be displayed vertically centered at the right:
以及我迄今为止尝试过的所有解决方案:
And every solution which i tried until now:
根本没有工作.他们拉长了图标,或者底线丢失了,或者其他什么地方完全出错了.我只想要另一个箭头.
simply werent working. They had stretched icons or the bottom line was missing or something else went totally wrong. I just want another arrow.
推荐答案
尝试使用以下样式对您的微调框应用
Try applying following style to your spinner using
style="@style/SpinnerTheme"
//微调样式:
<style name="SpinnerTheme" parent="android:Widget.Spinner">
<item name="android:background">@drawable/bg_spinner</item>
</style>
// bg_spinner.xml 用箭头替换arrow_down_gray
//bg_spinner.xml Replace the arrow_down_gray with your arrow
<?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="0.33dp" android:color="#0fb1fa" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="@drawable/arrow_down_gray" />
</item>
</layer-list>
</item>
</selector>
这篇关于更改微调框下拉图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!