且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的 - 更改自定义微调的DropDownItem风格

更新时间:2023-11-26 23:41:10

在创建绘制文件夹中的XML与任何名称,例如 spinner_bg.xml 并添加以下行

Create an XML in drawable folder with any name for example spinner_bg.xml and add the following lines

<?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="1dp" android:color="#504a4b" />

                <corners android:radius="5dp" />

                <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
            </shape></item>
        <item ><bitmap android:gravity="bottom|right" android:src="@drawable/spinner_ab_default_holo_dark_am" />   // you can use any other image here, instead of default_holo_dark_am
        </item>
      </layer-list></item>

 </selector>  

添加以下行到你的 styles.xml 这是内部价值观的文件夹

Add the following lines to your styles.xml which is inside values folder

  <style name="spinner_style" >
        <item name="android:background">@drawable/spinner_bg</item>
        <item name="android:layout_marginLeft">10dp</item>
        <item name="android:layout_marginRight">10dp</item>
        <item name="android:layout_marginBottom">10dp</item>
        <item name="android:paddingLeft">8dp</item>
        <item name="android:paddingTop">5dp</item>
        <item name="android:paddingBottom">5dp</item>

现在添加这种风格到您的微调为

Now add this style to your spinner as

<Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/spinner_style"
            android:popupBackground="#cccccc" />