如何创建一个带有三角形下拉箭头的矩形框的微调器?

时间:2016-08-20 04:53:57

标签: android android-layout android-spinner stroke

我需要创建一个带有三角形下拉箭头的矩形边框的微调器。如何创建这样的微调器?我试过,但我的实际输出与预期输出不同。 这是预期的产出。

enter image description here

但我的输出看起来像这样。

enter image description here

如何使用带有矩形框的下拉图像创建微调器?

这是我申请的代码。

       <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="1dip"
        android:orientation="vertical" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Preferred contact method">
        </TextView>
        <Spinner
            android:id="@+id/account_spinner"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_marginTop="2dp"
            style="@style/Base.Widget.AppCompat.Spinner.Underlined"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Telephone">
        </TextView>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:inputType="phone"
            android:ems="10"
            android:background="@drawable/edittext_border"
            android:id="@+id/editText" />

EditText border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />

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

但是如何申请带有三角形箭头和外部矩形边框的微调器?

提前致谢。

2 个答案:

答案 0 :(得分:1)

它只是在XML布局预览中呈现,因为Preview不知道要绑定到微调器的数据。一旦在设备或模拟器上运行它,它将看起来像带有下拉箭头的普通微调器。

答案 1 :(得分:1)

您可以在现有背景图片的Android SDK文件夹中查看下拉列表。示例位于{sdk_folder}\platforms\android-{xx}\data\res\drawable-{density}\dropdown_normal_holo_dark.9.png。这只是定义一个所谓的9-patch drawable并将其应用于你的下拉风格的问题。

这解释了如何创建一个这样的drawable(并且还有关于9-patch是什么的解释的链接):https://developer.android.com/studio/write/draw9patch.html