无法更改微调器下拉图标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法更改微调器下拉图标相关的知识,希望对你有一定的参考价值。

我想将微调器下拉图标更改为我经过堆栈线程的位置图标,我根据这做了修改。这就是它

 <Spinner
        android:id="@+id/spinner22"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        style="@style/SpinnerTheme"
        android:gravity="end" />

在style.xml和style.xml(v21)中我做了

<style name="SpinnerTheme" parent="android:Widget.Spinner">
<item name="android:background">@drawable/bg_spinner</item>

我创建了一个可绘制的资源文件

<?xml version="1.0" encoding="utf-8"?>

<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/spinnericon" />

        </item>

    </layer-list>

</item>

这是我的spinnericon.xml可绘制资源文件

<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>

Java代码

    Spinner spinner12 = (Spinner) findViewById(R.id.spinner22);
    final TextView tv1 = (TextView) findViewById(R.id.tv1);

    String[] plants12 = new String[]
            "LOCATIONS",
            "Mangalore",
            "Bangalore (coming soon)",

    ;

    ArrayAdapter<String> spinnerArrayAdapter1 = new ArrayAdapter<String>(
            this,android.R.layout.simple_spinner_item,plants12
    );



    spinnerArrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);


    spinner12.setAdapter(spinnerArrayAdapter1);

这是我在android studio中的预览

screenshot

错误日志cat(小部分)

 Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #61: Error inflating class Spinner
 Caused by: android.view.InflateException: Binary XML file line #61: Error inflating class Spinner
 Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.EduMangalore:drawable/bg_spinner with resource ID #0x7f070067
 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/bg_spinner.xml from drawable resource ID #0x7f070067

谁能帮我

答案

尝试使用以下样式应用于您的微调器

  style="@style/SpinnerTheme"

<style name="SpinnerTheme" parent="android:Widget.Spinner">
<item name="android:background">@drawable/bg_spinner</item>
</style>

用箭头替换arrow_down_gray

<?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>

以上是关于无法更改微调器下拉图标的主要内容,如果未能解决你的问题,请参考以下文章

Android微调器下拉菜单背景颜色更改

Android Spinner:删除文本和下拉图标之间的多余空格

更改暴露下拉菜单的背景颜色

如何设置微调器下拉列表的最大长度?

Android:减小微调器下拉框的宽度

如何从微调器下拉 CHOICES 自定义样式?