jomin_george94 jomin_george94 - 26 days ago 30
Android Question

Android Spinner Dropdown arrow not displaying

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

Answer

Simplest method is Set background image (with arrow) instead of color.

 spinner.setBackgroundResource(R.drawable.spinner_img);

hope it helps.

Comments