数字选择器文本颜色

3
我有一个包含每行一个TextView和NumberPicker的ListView。每当我启动活动时,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>

-

...而且还有很多其他的...


黑色的十六进制代码是 #000000。 - ClaireG
3
@g00dy 供您参考 > http://www.color-hex.com/color/000000 - ClaireG
抱歉 - 我的错,要设置 numberPicker 的样式,请使用类似这样的代码 - <style name="npColour" parent="@style/Holo.NumberPicker"> <item name="selectionDivider">#ff5500</item> </style>` 看看是否有效。 - g00dy
你甚至可以进一步自定义 - <item name="numberPickerStyle">@style/Theme.Holo.NumberPicker</item> - g00dy
1
找不到与“@style/Theme.Holo.NumberPicker”匹配的资源。 - ClaireG
显示剩余2条评论
2个回答

2
我知道这个问题已经很老了。我在这里找到了答案:更改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;
}

-3
你正在使用格式化程序吗?我不得不使用setDisplayedValues来解决这个问题。 我假设你已经解决了这个问题,但是我还是要发布这个帖子,因为我曾经绝望地寻找答案,最后是意外解决的。
    NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(5);     
    String[] periodicityValues = {"Semanal", "Mensal", "Bimestral", "Trimestral", "Semestral", "Anual"};
    numberPicker.setDisplayedValues(periodicityValues);

2
这会如何改变文本颜色? - Someone Somewhere
1
准确地说,它将如何改变文本颜色? - Ritesh Kumar Singh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接