Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Spinner Dropdown arrow not displaying

Tags:

my background for my fragment is white, and the arrow for the spinner does not display unless I click on it.

This is the snippet from my Java file:

    spinner = (Spinner)v.findViewById(R.id.spinner);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.accounts,R.layout.spinner_item);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_items);
    spinner.setAdapter(adapter);
    spinner.setPrompt("Select an account");

This is my XMLfor the spinner_item

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textSize="16dp"
android:background="#FFFFFFFF"
android:textColor="#ff252525"/>

And this is my layout for my spinner_dropdown_items.

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textSize="16dp"
android:background="#FFFFFFFF"
android:textColor="#ff252525"/>

This is how my spinner looks with a white background to my fragment: White Colour Background - Spinner And this is how it looks when I change my background colour to purple: Purple background - Spinner

like image 810
dark_illusion_909099 Avatar asked Mar 12 '15 12:03

dark_illusion_909099


People also ask

How to show data in spinner in android?

Use ArrayAdapter to store the courses list. Create a single MainActivity that contains the spinner and on clicking any item of spinner Toast with that course name will be shown. Creating the activities: There will be one activity and hence one XML file for MainActivity. activity_main.


2 Answers

This works for me, much simpler as well:

<Spinner
      android:id="@+id/spinner"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:theme="@style/ThemeOverlay.AppCompat.Light"
      android:spinnerMode="dropdown" />

And in your class file:

spinner = (Spinner) view.findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

Hope this helps ;)

like image 194
Jiyeh Avatar answered Oct 26 '22 22:10

Jiyeh


Try this one:

<Spinner
     android:id="@+id/spinnPhoneTypes"
     android:layout_width="0dp"
     style="@android:style/Widget.Spinner.DropDown"
     android:layout_height="@dimen/thirtyFive"
     android:layout_marginLeft="10dp"
     android:layout_weight="1"
     android:background="@drawable/shape_drop_down_normal"
     android:gravity="center_vertical" />

shape_drop_down_normal.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape>
            <solid android:color="@android:color/transparent" />

            <stroke
                android:width="1dp"
                android:color="#6f94c7" />

            <padding
                android:bottom="10dp"
                android:left="2dp"
                android:right="10dp"
                android:top="10dp" />
        </shape>
    </item>
    <item>
        <bitmap
            android:gravity="end"
            android:src="@drawable/drop_arrow" />
    </item>
</layer-list>
like image 33
kalidoss rajendran Avatar answered Oct 26 '22 23:10

kalidoss rajendran