无法更改微调框下拉图标

时间:2019-04-15 05:22:01

标签: android xml android-spinner

我想将微调框下拉图标更改为我通过堆栈线程的位置图标,并根据此进行了修改。这就是它

 <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

错误日志猫(一小部分)

 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

谁能帮我

1 个答案:

答案 0 :(得分:0)

尝试使用以下样式对您的微调框应用

  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>