Android-更改自定义微调器';s下拉项样式

Android-更改自定义微调器';s下拉项样式,android,android-layout,android-spinner,android-styles,Android,Android Layout,Android Spinner,Android Styles,我有一个自定义微调器,我正在尝试替换DropDownSelector中的9面片背景/三角形 但我就是不能让它正常工作。我最终得到(白框是一个测试资产): 新的9补丁显示出来了,但是它弄乱了填充,看起来像一个旋转器里面的旋转器 下面是没有添加9补丁时的情况: 这就是我想要它看起来的样子,但是使用新的9patch而不是旧的9patch,而不是Spinner中的Spinner效果 这是我的密码: <RelativeLayout xmlns:android="http://schemas.an

我有一个自定义微调器,我正在尝试替换DropDownSelector中的9面片背景/三角形

但我就是不能让它正常工作。我最终得到(白框是一个测试资产):

新的9补丁显示出来了,但是它弄乱了填充,看起来像一个旋转器里面的旋转器

下面是没有添加9补丁时的情况:

这就是我想要它看起来的样子,但是使用新的9patch而不是旧的9patch,而不是Spinner中的Spinner效果

这是我的密码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

   <Spinner xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/spinner2"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_alignParentRight="true"
             android:gravity="center_horizontal"/>

</RelativeLayout>
这是适配器的CustomSpinnerTitleLayout设置:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                style="?android:attr/spinnerDropDownItemStyle"
                android:paddingRight="0dp"   >
    <ImageView

            android:id="@+id/spinner_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"
            android:layout_gravity="center"
            android:paddingRight="0dp"
            />

</LinearLayout>

这就是我添加9补丁的主题

<resources>
    <style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:spinnerDropDownItemStyle">@style/customActionBarDropDownStyle</item>
    </style>


    <style name="customActionBarDropDownStyle" parent="@android:style/Widget.Holo.Light.ListView" >
           <item name="android:background">@drawable/spinner9patch</item>
    </style>
</resources>

@样式/自定义操作BarDropDownStyle
@可拉丝/喷丝头9Patch
我显然做错了什么,但是什么?我尝试在第一个布局文件中的微调器上设置spinnerDropDownItemStyle和spinnerStyle,但什么都没做。我做错了什么


提前谢谢

我真的建议您查看这个在线生成器,只需制作自定义微调器,然后下载文件

在drawable文件夹中使用任何名称创建一个XML,例如
spinner_bg.XML
,并添加以下行

<?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>  
现在将此样式添加到微调器中,如下所示:

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


请尝试查看这些链接,谢谢!完全有效。但有一个问题:所以,要明确的是,这种方式微调器使用微调器_样式,并且不会从其父级继承任何内容,对吗?另外,我应该将该选项放在哪里,以便它不会删除可绘制位图?谢谢
  <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>
<Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/spinner_style"
            android:popupBackground="#cccccc" />