Java – Android eclipse all spinner fonts turn white

In my project, all spinner fonts suddenly turn white, which is why I can't find it They were all black before For example, in the spinner, the drop-down list is all white Its 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 ensure that I add #000000 to all relevant locations, but the list is still white Fill the spinner with the following methods:;

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 gave simple_ spinner_ Item and simple_ spinner_ dropdown_ Item added black, but it still hasn't changed In the Java section, I didn't do anything about color What are the possible reasons why all these texts turn white?

Edit: only the spinner has a problem I can change the text color of other elements But even if I insert textcolor: "#000000" anywhere related to the spinner, I can't change the spinner

Solution

Found a reason

When I worked with other spinners in other programs, I realized that this strange fact caused the font to turn white Even if the problem looks like a style problem, the root cause lies in the application context In my old code, I filled spinner with the following code;

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),list);

Then I changed the context parameter, as shown below;

ArrayAdapter<String> adapter= new ArrayAdapter<String>(MainActivity.this,list);

Then all the unpopular white fonts turn black!

If getapplicationcontext () is used as a context parameter, some styles may be incorrect Therefore, try hard coding the call context directly, such as youractivity. Com in the adapter This will solve the problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>