I know this question has been asked a lot (see: How to customize a Spinner in Android, How to change layout of spinner in Android, How to change spinner text size and text color?, How to change spinner text color)
All the answers suggest to create a custom_spinner.xml file to accomplish this task. This file must be something like this:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:singleLine="true"
android:textColor="@color/#FFFFFF" />
However, no one says where to locate this file. In this answer https://stackoverflow.com/a/37859442/5616178 says this file must be in Drawable folder, but when I do that, an "Element TextView must be declared" error is raised by Android Studio. When I locate it in the layout folder, the R.layout won't resolve it either.
Thank you for your answers.
EDIT
I was able to solve the problem. As many of you said, the file must be located inside the res/layout
since it's a layout resource. At first, my code looked like this:
citiesSpinner.setAdapter(
new ArrayAdapter<String>(SignUp.this,
android.R.layout.custom_spinner,
cityNames)
);
When I declared the adapter outside the constructor, i.e.:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
SignUp.this,
R.layout.custom_spinner,
cityNames);
citiesSpinner.setAdapter(adapter);
The R class was able to resolve the layout. I don't know why that happens, it would be useful if someone can explain it. Thank you again for your answers!