找到你要的答案

Q:How to add cancel button to spinner dialog?

Q:如何添加取消按钮,旋转对话框?

I have a spinner with its mode set to 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" />

How can I a Cancel button to its 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" />

我怎样才能取消对话框的按钮?

answer1: 回答1:

The only way is to create your own custom spinner, like:

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

Important things need to be implemented:

  1. protected onDraw() - which would actually draw your MySpinner + button
  2. protected void onMeasure(int widthSpec, int heightSpec) - defines size of your custom spinner

Here's a link to tutorial which covers basics of custom widgets

唯一的方法是创建您自己的自定义飞旋,像:

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

需要实施的重要事项:

  1. protected onDraw() - which would actually draw your MySpinner + button
  2. protected void onMeasure(int widthSpec, int heightSpec) - defines size of your custom spinner

这里有一个链接的教程,其中包括基本的自定义部件

android  spinner