如何将取消按钮添加到微调对话框?

How to add cancel button to spinner dialog?

我有一个 spinner,其模式设置为 dialog:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner1"
            android:spinnerMode="dialog"
            android:dropDownWidth="match_parent"
            android:textAppearance="@style/TextAppearance.Medium"
            android:prompt="@string/label_selection" />

如何在其对话框中添加取消按钮?

唯一的方法是创建自己的自定义微调器,例如:

public class MySpinner extends Spinner implements OnClickListener {
   //blah-blah
}

需要执行的重要事项:

  1. protected onDraw() - 这实际上会绘制您的 MySpinner + 按钮
  2. protected void onMeasure(int widthSpec, int heightSpec) - 定义自定义微调器的大小

Here's a link 至涵盖自定义小部件基础知识的教程