如何在右侧带有向下三角形的微调器周围创建自定义微调器之类的边框? [英] How to create custom spinner like border around the spinner with down triangle on the right side?

查看:15
本文介绍了如何在右侧带有向下三角形的微调器周围创建自定义微调器之类的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发自定义微调器,例如右下角带有三角形的微调器周围的线.
像下图

I want to develop custom spinner like line around spinner with triangle at right bottom corner.
like following image

对于上面的无花果我写了我的自定义微调器

For above fig I wrote my custom spinner like a

spinner.xml

spinner.xml

 <Spinner android:background="@drawable/spinner_background"/>

spinner_background.xml

spinner_background.xml

<?xml version="1.0" encoding="UTF-8"?>

<item android:state_pressed="true"
      android:drawable="@drawable/spinner_ab_pressed_new_theme_bs">
    <shape>

        <solid 
            android:color="@color/White" />

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

        <padding 
            android:bottom="10dp" 
            android:left="10dp" 
            android:right="10dp" 
            android:top="10dp" />

         <stroke 
            android:width="2dp" 
            android:color="@color/skyblue" />
    </shape>
 </item>
 <!-- spinner_ab_default_new_theme_bs -> this image for corner triangle -->
<item

    android:drawable="@drawable/spinner_ab_default_new_theme_bs" >
    <shape>
        <solid
            android:color="@color/White">
        </solid>

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

        <padding
            android:bottom="10dp" 
            android:left="10dp" 
            android:right="10dp" 
            android:top="10dp" />
         <stroke 
            android:width="2dp" 
            android:color="@color/gray"/>
    </shape>
</item>

我得到了如下图所示的输出

And I got output like following image

我尝试了很多,但没有实现我的目标,请任何人有开发微调器的解决方案.
就像上面的第一张图片.

I tried lot but not achieve my goal please anybody have solution to develop spinner.
like above first one image.

推荐答案

Spinner

<Spinner
    android:id="@+id/To_Units"
    style="@style/spinner_style" />

style.xml

    <style name="spinner_style">
          <item name="android:layout_width">match_parent</item>
          <item name="android:layout_height">wrap_content</item>
          <item name="android:background">@drawable/gradient_spinner</item>
          <item name="android:layout_margin">10dp</item>
          <item name="android:paddingLeft">8dp</item>
          <item name="android:paddingRight">20dp</item>
          <item name="android:paddingTop">5dp</item>
          <item name="android:paddingBottom">5dp</item>
          <item name="android:popupBackground">#DFFFFFFF</item>
     </style>

gradient_spinner.xml(在 drawable 文件夹中)

gradient_spinner.xml (in drawable folder)

<?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="#B3BBCC" android:startColor="#E8EBEF" android:type="linear" />

                    <stroke android:width="1dp" android:color="#000000" />

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

                    <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_arrow" />
            </item>
        </layer-list></item>

</selector>  

@drawable/spinner_arrow 是你的右下角图片

这篇关于如何在右侧带有向下三角形的微调器周围创建自定义微调器之类的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆