it-swarm.com.de

Android: Spinner Dropdown-Ansicht ändern

Meine Anwendung Ich möchte die untenstehende Spinner Dropdown-Ansicht.enter image description here Für diese Art von Spinner-Ansicht. Ich habe diesen Code geschrieben.

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.spinner, Android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(Android.R.layout.simple_spinner_dropdown_item);
    spinner_obj.setAdapter(adapter);

Ich habe dies von http://developer.Android.com/guide/topics/ui/controls/spinner.html Bekommen. Aber was ich habe, ist enter image description here

Bitte geben Sie mir den besten Weg, dies zu tun ....

9
Sridhar

Eine Art Wiederaufleben eines alten Beitrags hier, aber die akzeptierte Antwort ist alles andere als ideal. Der korrekte Weg, dies zu tun, besteht darin, den Spinner auf den Dropdown-Modus in Ihrer Layout-XML zu setzen:

<Spinner 
    Android:id="@+id/my_spinner"
    ...
    Android:spinnerMode="dropdown"/>

Die verfügbaren Optionen sind "Dialog" und "Dropdown".

30
Stephen Kidson

Ihre Anwendung läuft nach einem alten Thema.

Wenn Sie Android 4.2 verwenden, setzen Sie das Android-Anwendungsdesign (in der Manifestdatei) auf 

 Android:theme="@Android:style/Theme.Holo.Light"

OR

 Android:theme="@Android:style/Theme.Holo.Light.DarkActionBar"
8
Vipul Shah

möglicherweise laufen Sie in weniger als 4.0, 4.0 zeigt Ihnen das Dropdown als Bild an

2
Sanket Kachhela

Für die GUI HoloEverywhere verwenden. https://github.com/Prototik/HoloEverywhere HoloEverywhere ist der beste Weg, wenn Sie auf älteren Android-Versionen 4.0 das Holo-Design verwenden möchten.

Und für das Dropdown verwenden Sie Android: spinnerMode = "Dropdown" im Layout, wie Stephen Kidson erwähnt hat.

1
Mikael Svensson

Sie können Popup wie folgt verwenden:

           spinner=(EditText)findViewById(R.id.txt_Spinner);


        spinner.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                p = new Point();
                p.x = location[0]+(v.getHeight());
                p.y = location[1]+v.getHeight();

                if (p != null)
                    showPopup(statusActivity.this, p);

                System.out.println("show popup");
            }
        });




    // The method that displays the popup.
    private void showPopup(final Activity context, Point p) {
        int popupWidth = 300;
        int popupHeight = 500;

        // Inflate the popup_layout.xml
        LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
        LayoutInflater layoutInflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);

        // Creating the PopupWindow
        popup = new PopupWindow(context);
        popup.setContentView(layout);
        popup.setWidth(popupWidth);
        popup.setHeight(popupHeight);
        popup.setFocusable(true);

        // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
        int OFFSET_X = 00;
        int OFFSET_Y = 00;

        // Clear the default translucent background
        popup.setBackgroundDrawable(new BitmapDrawable());

        // Displaying the popup at the specified location, + offsets.
        popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
        ((TextView)layout.findViewById(R.id.textView2)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView3)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView4)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView5)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView6)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView7)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView8)).setClickable(true);
        ((TextView)layout.findViewById(R.id.textView9)).setClickable(true);

    }

and popup.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:id="@+id/popup"
    Android:layout_width="wrap_content"
    Android:layout_height="wrap_content"
    Android:background="@drawable/popup_bg"
    Android:orientation="vertical" >

    <TextView
        Android:id="@+id/textView1"
        style="@style/text_orange_heading"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:text="Select Status"
        Android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        Android:id="@+id/textView2"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="Sleeping"
        Android:text="Sleeping" />

    <TextView
        Android:id="@+id/textView3"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="Available"
        Android:text="Available" />

    <TextView
        Android:id="@+id/textView4"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="Busy"
        Android:text="Busy" />

    <TextView
        Android:id="@+id/textView5"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="At work"
        Android:text="At work" />

    <TextView
        Android:id="@+id/textView6"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="Battery charge low"
        Android:text="Battery charge low" />

    <TextView
        Android:id="@+id/textView7"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="In meeting"
        Android:text="In meeting" />

    <TextView
        Android:id="@+id/textView8"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="TMS me later"
        Android:text="TMS me later" />

    <TextView
        Android:id="@+id/textView9"
        style="@style/text_blue_contains"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:onClick="onClick"
        Android:clickable="true"
        Android:drawableBottom="@drawable/line_white"
        Android:tag="At the toilet"
        Android:text="At the toilet" />

    <EditText
        Android:id="@+id/textCustomize"
        style="@style/text_blue_contains"
        Android:layout_width="fill_parent"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="5dp"
        Android:tag="Customize"
        Android:text="Customize" />

</LinearLayout>
1
Parker