Android Eclipse all Spinner fonts turned white

In my project, all Spinner fonts suddenly turned white for a reason that I cannot find. Before, everyone was black. For example, in the spinner, a drop-down list appears in white. This 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" /> 

To make sure, I added # 000000 to all related places, but the list is still white. Spinner is populated in the following way:

 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, but still no changes. In the Java part, I am not doing anything related to color. What can cause all these texts to be white?

Edit: Only spins have a problem. I can change the text colors of other elements. But I cannot change the spinners, although I inserted textColor: "# 000000" anywhere on the spinners.

+6
source share
4 answers

Reason found.

While I worked on other spinners in another program, I realized that this strange fact made the font turn white. Even this question looks like a style issue, the main reason is the application context. In my old code, I used the following code to populate 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 the unwanted white fonts turned black !!

If you use getApplicationContext() as a context parameter, some of your styles may be incorrect. Therefore, trying to invoke a context hardcoded as YourActivity.this in the adapter will solve the problem.

+7
source

The theme style applied to your project may cause this problem, try changing the theme attribute in the manifest . All text of the application text can only be changed with the theme style. try removing the theme tag from the manifest file and checking the color, if it changes to the default value, then you can create your own theme with any colored text that will be applied to it.

+2
source

Create the xml file spinner_dropdown_item.xml and paste the 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 the 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); 
+1
source

You may have accidentally changed the application theme in the layout. So you just need to change the subject. Go to any layout and open in the graphic layout, then you can see the application theme option in the upper palette. Change it to any white. And to change the whole themes of the app’s layout, you can do this in manifest.like below.

 <application android:theme="@style/AppTheme" >---- </application> 
0
source

Source: https://habr.com/ru/post/973957/


All Articles