Android 在微调器中更改选定项目的颜色

Android 在微调器中更改选定项目的颜色,android,spinner,android-spinner,Android,Spinner,Android Spinner,由于某些原因,“我的微调器”中选定项的文本颜色为白色。以下是活动的代码: spinner = (Spinner) findViewById(R.id.spinner_categories); arr_list_categories = manager.get_all_categories(); arr_list_categories_names = new ArrayList<String>(); // Loop through the Categories array for (i

由于某些原因,“我的微调器”中选定项的文本颜色为白色。以下是活动的代码:

spinner = (Spinner) findViewById(R.id.spinner_categories);
arr_list_categories = manager.get_all_categories();
arr_list_categories_names = new ArrayList<String>();
// Loop through the Categories array
for (int i = 0; i < arr_list_categories.size(); i++) 
{
    Category curr_category = arr_list_categories.get(i); // Get the Category object at current position
    arr_list_categories_names.add(curr_category.getCategory_name()
            .toString()); // Add the name of the Category to the Names Array        
}
// Setting the Adapter, to display retrieved data in the Spinner
adapter=new ArrayAdapter<String> (this, R.layout.simple_spinner_item, arr_list_categories_names);
// Setting the display source for the Spinner View
adapter.setDropDownViewResource(R.layout.simple_spinner_item);
// Populating the Spinner
spinner.setAdapter(adapter);
// Registering for On Item Selected listener
spinner.setOnItemSelectedListener(spinnerListener);
但所选项目的文本颜色仍然为白色。所以我试着在OnItemSelectedListener中这样做:

TextView selected_tv = (TextView) parent.getChildAt(0);
selected_tv.setTextColor(Color.BLUE);
还是白的

为什么会发生这种情况?我该如何解决?谢谢大家!

TextView selected_tv = (TextView) parent.getChildAt(0);
selected_tv.setTextColor(Color.BLUE);
在此代码中,第一行中的更改如下所示使用TextView的id:

TextView selected_tv = (TextView) parent.findViewById(R.id.selected_tv);
selected_tv.setTextColor(Color.BLUE);

我也遇到了同样的问题。我只是将ArrayAdapter this更改为ArrayAdapter classname.this.Don't know我是否为你工作我尝试了你的代码。它工作正常。。显示选定文本的红色。@Sania尝试过,但它仍然显示白色文本…@NibhaJain这太奇怪了。。。出于某种原因,我在模拟器和实际设备上都看到了白色文本。原因可能是什么?不要紧,我发现了问题-有一个影响所选项目颜色的代码。愚蠢的我-没有检查我从我的旧项目带来的代码。。。
TextView selected_tv = (TextView) parent.getChildAt(0);
selected_tv.setTextColor(Color.BLUE);
TextView selected_tv = (TextView) parent.findViewById(R.id.selected_tv);
selected_tv.setTextColor(Color.BLUE);