5

In my project, all Spinner fonts suddenly became white for a reason I can't find. Before all of them were black. For example, in a spinner, the dropdown list comes all in white. It's XML file is as follows;

<Spinner
    android:id="@+id/mainactivity_spinner_city"
    android:fontFamily="Roboto"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainactivity_imageview_logo"
    android:layout_marginTop="15dp"  />

In order to make sure, I added #000000 to all related places, but the list is still white. The spinner gets populated with the following method;

ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, list);
    dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter2);

So I added black color to simple_spinner_item and simple_spinner_dropdown_item as well but still no change. In Java part, I do not do anything related to color. What may be causing all these texts being white?

Edit: Only spinners have problem. I can change other elemens' text colors. But I can't change spinners even though I inserted textColor:"#000000" to anywhere related with spinners.

Kai
  • 38,985
  • 14
  • 88
  • 103
Faruk Yazici
  • 2,344
  • 18
  • 38

4 Answers4

7

Reason has been found.

While I was tackling with other spinners in other program, I realized that this strange fact caused the font becoming white. Even this question looks like a styling problem, underlying reason is about application context. In my old code, I used the following code for populating Spinner;

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, list);

Then I changed the context parameter as follows;

ArrayAdapter<String> adapter= new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, list);

Then all undesired white fonts became black!!

If you use getApplicationContext() as a context parameter, some of your styling may be improper. So trying to call the context directly hardcoded like YourActivity.this in the adapter will solve the problem.

Faruk Yazici
  • 2,344
  • 18
  • 38
  • 1
    Now what's important is why it happens: application context is not fit for inflating views, because it uses the default system theme and not the application theme (even though the context is defined for the application). See http://www.doubleencore.com/2013/06/context/ for information about contexts and their usage; this answer http://stackoverflow.com/a/25116293/734151 helped me. – personne3000 Nov 10 '14 at 18:28
1

The theme style applied to your project may cause this problem, try changing the theme attribute in you manifest.The whole app text color only can get changed from the theme style. try removing the theme tag from manifest file, and check color if it changes to default then you can create your own theme with any color text to apply on it.

Raviindra
  • 114
  • 1
  • 7
0

You might have changed the app theme accidentally in layout. So you just need to change the theme. Go to any layout and open in graphic layout then you can see app theme option at top palette. Change that to any white.And to change entire app layout themes you can do that in manifest.like below.

<application android:theme="@style/AppTheme" >---- </application>
Ram
  • 114
  • 12
  • Spinners are still only white. Other elements have no problem. – Faruk Yazici Aug 18 '14 at 07:26
  • I think that is due to OS system as you are supplying system layout in adapter like android.R.layout.simple_spinner_item. So you create own layout to display elements with textview in it and apply to arrayadapter. – Ram Aug 18 '14 at 09:14
0

Create xml file spinner_dropdown_item.xml and paste following code :

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="#000000"
android:textSize="23sp" 
android:padding="17dip"/>

In your .java file add code :

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                            getApplicationContext(),
                            android.R.layout.simple_spinner_item, list);
//This line sets spinner_dropdown_item.xml as your spinner item
dataAdapter
        .setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
Paritosh
  • 2,097
  • 3
  • 30
  • 42