【问题标题】:Styling Android Spinner样式化 Android 微调器
【发布时间】:2015-06-27 12:33:23
【问题描述】:

是否可以像下图那样设置带有边框和箭头的 Android Spinner 样式?

【问题讨论】:

  • 是的,这是可能的。使用 9-patch 作为微调器的背景。
  • 有没有其他不使用图片的方法,比如画形状?
  • 编写自定义视图扩展微调器并覆盖 ondraw 方法。

标签: android styles spinner draw


【解决方案1】:

您可以使用九个补丁图像。自定义微调器,如下所示

【讨论】:

    【解决方案2】:

    我找到了我想做的解决方案,如下所示。

    <Spinner
    android:id="@+id/genderBox"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:background="@drawable/my_spinner"
    />
    

    并在drawable文件夹中创建一个xml文件并粘贴以下代码

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
    <shape>
    <solid android:color="@android:color/white" />
    
    <stroke
    android:width="1dp"
    android:color="#d2d2d2" />
    
    <padding
    android:bottom="0dp"
    android:left="0dp"
    android:right="10dp"
    android:top="0dp" />
    </shape>
    </item>
    <item>
    <bitmap
    android:gravity="end"
    android:src="@drawable/dropdown_arrow" />
    </item>
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多