简体   繁体   English

微调框默认文本颜色为白色?

[英]Spinner default text color white?

I would like to change the color of the default value of my spinner. 我想更改微调器默认值的颜色。

This value is white for no reason, how can I fix the text color of this default value to black? 此值无缘无故是白色,如何将默认值的文本颜色固定为黑色?

Illustration: 插图:

ArrayAdapter<String> adapter;
List<String> list;

list=new ArrayList<String>();
list.add("0.01");
list.add("0.10");
list.add("1.00");
list.add("10.0");
list.add("100");
adapter= new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item,list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_pas.setAdapter(adapter);
spinner_pas.setSelection(2);

Add the below line into the xml - android.R.layout.simple_spinner_item 将以下行添加到xml-android.R.layout.simple_spinner_item

 android:background="@color/black"
 android:textColor="@color/white"

Create a custom theme for Spinner like this 像这样为Spinner创建自定义主题

<style name="CustomSpinnerTheme" 
  parent="Base.Widget.AppCompat.DropDownItem.Spinner">
    <item name="android:textColor">#000000</item>
    <item name="android:background">#ffffff</item>
</style>

and apply it here 并在这里应用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM