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
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.
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 ;)
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With