The text on my spinners is white, and I have no idea why.
This is my xml, nothing special
<Spinner
android:id="@+id/spinner_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
And my code
dateSpinner = (Spinner) findViewById(R.id.spinner_date);
selectedDate = calendar.getTime();
List<String> list = new ArrayList<String>();
list.add(formatter.format(selectedDate));
dateAdapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_spinner_item, list);
dateSpinner.setAdapter(dateAdapter);
What could be the reason that my text is displayed in white?
EDIT: I've found the reason, I replaced the mContext parameter which was set in my onCreate.
mContext = getApplicationContext();
Now I use d
ateAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
and it works.
I have same problem and have found the answer. You dont use application context, instead, just use getActivity()
(if you are in fragment) or this (if you are in activity), it will work
dateAdapter = new ArrayAdapter<String>(**this**,
android.R.layout.simple_spinner_item, list);
I solved this problem using
getBaseContext()
instead of
getApplicationContext()
i change it from
new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, some_list);
to
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
it's fixed, although i don't want to use "this"
I also had same problem it was because of my application theme. Which I solved by replacing the
android.R.layout.simple_spinner_item
with
android.R.layout.simple_list_item_1
in my ArrayAdapter
. I hope this may solve your problem
I've changed the text color of that spinner's textview without creating a new layout. I know it's been a long time but it's what worked for me, just thought of sharing it. Best part is you can use it on any default adapter.
Here's the code : (this for Activity & requireActivity for Fragments)
1) Java
arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,groups){
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView listItem = view.findViewById(android.R.id.text1);
listItem.setTextColor(Color.WHITE);
listItem.setTextSize(20);
listItem.setElevation(18);
return view;
}
};
2) Kotlin
arrayAdapter = object : ArrayAdapter<String>(requireActivity(), android.R.layout.simple_spinner_item, spinnerCategoriesList) {
override fun getView(position: Int, @Nullable convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)
val listItem = view.findViewById<TextView>(android.R.id.text1)
listItem.setTextColor(Color.BLACK)
listItem.textSize = 16f
return view
}
}
Maybe you have a white android:textColor="@android:color/white"
attribute in your simple_spinner_item.xml in the layout folder of your project.
Better use a custom spinner item layout with a good android:textColor="@android:color/COLOR_YOU_WANT_TO_USE"
attribute.
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