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

Android 如何将“取消”按钮添加到微调器对话框?,android,spinner,Android,Spinner,我有一个微调器,其模式设置为对话框: <Spinner android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/spinner1" android:spinnerMode="dialog" android:dropDownWidth=

我有一个
微调器
,其模式设置为
对话框

        <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
}
需要实施的重要事项:

  • protected onDraw()
    -这将实际绘制您的
    MySpinner
    +按钮
  • protectedvoidonmeasure(int-widthSpec,int-heightSpec)
    -定义自定义微调器的大小
  • 到包含自定义小部件基础知识的教程