我的代码是风格
这是在style.xml
中<style name="SpinnerTheme">
<item name="android:background" >@drawable/bg_spinner</item>
</style>
bg_spinner.xml
<item>
<layer-list>
<item >
<bitmap android:gravity="bottom" android:src="@drawable/under_line" />
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="@drawable/dropdown" />
</item>
</layer-list>
</item>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/SpinnerTheme"
android:layout_marginTop="15dp"
android:hint="Sex"
android:id="@+id/spinnerSex" />
日期,月份和年份是全宽度,背景图像也是宽度较小,但是当它出现性别时它没有显示全宽。 我需要性别全宽的底线,请做必要的
答案 0 :(得分:2)
您可以通过xml代码绘制线条。如下所示
<item >
<layer-list>
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<!-- background color of box -->
</shape>
</item>
<item
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#323232" />
<!-- color of stroke -->
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="@drawable/downlarrow" />
</item>
</layer-list>
</item>
答案 1 :(得分:0)
使用以下代码替换xml代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- Draw a 2dp width border around shape -->
<stroke
android:color="#000000"
android:width="2dp"
/>
</shape>
</item>
<!-- Overlap the left, top and right border using background color -->
<item
android:bottom="2dp"
>
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>