【问题标题】:Customize a Spinner to look like a button自定义 Spinner 使其看起来像一个按钮
【发布时间】:2020-02-24 18:43:38
【问题描述】:

我有一个自定义按钮定义如下

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <gradient android:angle="-90" android:startColor="@color/colorPrimaryDark" android:endColor="@color/colorAccent"  />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <solid android:color="@color/colorAccent"/>
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <gradient android:angle="-90" android:startColor="@color/colorPrimary" android:endColor="@color/colorPrimaryDark"  />
        </shape>
    </item>
</selector>

我想创建一个微调器,它在未单击时看起来像按钮,并且仅在按下时显示可选项目。默认微调器不是很漂亮,不适合我的设计。

有人知道如何实现吗?

【问题讨论】:

标签: android button spinner


【解决方案1】:
                            <Spinner
                            android:id="@+id/spinner_start_day_def"
                            android:layout_width="100dp"
                            android:layout_height="30dp"
                            android:layout_gravity="center"
                            android:background="@drawable/rounded_button"
                            android:gravity="center"
                            android:minWidth="70dp"
                            android:popupBackground="@color/colorPrimary"
                            android:textAlignment="center" />

这很简单,android:background="@drawable/rounded_button"

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2011-07-04
    • 2010-10-17
    • 1970-01-01
    相关资源
    最近更新 更多