java - 如何从微调器中的可绘制设置下拉箭头?
问题描述
我正在尝试将可绘制设置为 Spinner 中的箭头,但不支持位图。
我使用了 svg 文件(ic_arrow.xml)并将其设置在spinner_arrow.xml
文件中:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"
/>
<solid android:color="@color/white" />
<stroke android:width="2px" android:color="@color/grey" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<bitmap android:gravity="center|right" android:src="@drawable/ic_arrow"/>
</item>
</layer-list>
所以我用它作为布局文件的背景
<Spinner
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/spinner_arrow"/>
但我在显示 Spinner 时出错:“我的应用程序中的二进制 XML 文件第 41 行:layout/activity_registration_driver:错误膨胀类 Spinner”。
我认为问题在于在微调器中添加可绘制箭头,但我不知道如何解决它
解决方案
请使用以下代码添加带有微调器的箭头:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/btn_height_common"
android:layout_marginLeft="@dimen/_15sdp"
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginRight="@dimen/_15sdp"
android:background="@drawable/bg_editext">
<Spinner
android:id="@+id/sp_gender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:entries="@array/gender"
android:fontFamily="@font/gotham_narrow_book"
android:overlapAnchor="false"
android:paddingLeft="@dimen/_10sdp"
android:paddingRight="@dimen/_10sdp"
android:textColor="@color/gray_text_color"
android:textSize="@dimen/normal_textsize" />
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/_15sdp"
android:padding="@dimen/_2sdp"
android:src="@mipmap/ic_down_gray" />
</RelativeLayout>
输出:
推荐阅读
- mysql - TypeError: require(...) is not a function while Using sequalize with node js
- python - 如何使用 for 循环正确编写 jinja2 模板,
- python - 计算 Pandas 数据框中的值 -Python
- python - pandas - 绘制列的分布
- python - 在这两种情况下都提到了我,但是当我以不同的方式写它时它会给我一个错误
- javascript - 为什么 await 不能与 array.forEach 和 db 函数一起使用?
- jquery - 通过jquery jtable保存行会引发错误
- python - 如何进一步修改此代码以显示用户想要的感叹号数量?
- swagger - 将表单 swagger 1.5 升级到 2 或 3 的好处
- swift - 如何制作视图控制器 SKScene 的一部分并在同一屏幕上使用两者?