我有一个ListView
,其中包含一个TextView
和一个针对每一行的NumberPicker
。每当我启动活动时,NumberPicker
的数字都是白色的(与背景颜色相同)。
还有其他建议吗?
-
NumberPicker.xml
<NumberPicker
android:id="@+id/npMaterialAmount"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="75dp"
style="@style/npColour"/>
-
试用风格1:
<style name = "npColour" >
<item name = "android:textColor">#000000</item>
</style>
-
试用样式2:
<style name = "npColour" parent ="@android:style/Theme.Holo.Light">
</style>
-
...名单还在继续.
发布于 2015-03-13 01:25:47
我知道这个问题很老。我在这里创建了答案:更改NumberPicker的文本颜色
副本:
这段代码应该可以解决您的问题。您所遇到的问题是,在NumberPicker的构造过程中,它捕获EditText textColor并将其分配给一个油漆,这样它就可以用相同的颜色在编辑文本的上面和下面绘制数字。
import java.lang.reflect.Field;
public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color)
{
final int count = numberPicker.getChildCount();
for(int i = 0; i < count; i++){
View child = numberPicker.getChildAt(i);
if(child instanceof EditText){
try{
Field selectorWheelPaintField = numberPicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
((EditText)child).setTextColor(color);
numberPicker.invalidate();
return true;
}
catch(NoSuchFieldException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalAccessException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalArgumentException e){
Log.w("setNumberPickerTextColor", e);
}
}
}
return false;
}
发布于 2013-11-20 12:01:26
你用的是格式化程序吗?我不得不用setDisplayedValues来解决这个问题。我想你已经解决了这个问题,但我还是发了这个帖子,我一个人不顾一切地寻找答案,偶然解决了这个问题。
NumberPicker numberPicker = new NumberPicker(getActivity());
numberPicker.setMinValue(0);
numberPicker.setMaxValue(5);
String[] periodicityValues = {"Semanal", "Mensal", "Bimestral", "Trimestral", "Semestral", "Anual"};
numberPicker.setDisplayedValues(periodicityValues);
https://stackoverflow.com/questions/18120840
复制