【问题标题】:NumberPicker textColourNumberPicker textColor
【发布时间】:2013-08-09 20:38:12
【问题描述】:

我有一个ListView,每行包含一个TextView 和一个NumberPicker。 每当我启动活动时,NumberPicker 的数字都是白色的(与背景颜色相同)。

我尝试应用hereherehere 建议的样式;无济于事。

还有其他建议吗?

-

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>

-

...而且名单还在继续...

【问题讨论】:

  • 好吧,你将NumberPicker的颜色设置为白色-> &lt;item name = "android:textColor"&gt;#000000&lt;/item&gt;,你为什么想知道为什么它是白色的?
  • 黑色的十六进制代码是#000000
  • @g00dy 供您参考 > color-hex.com/color/000000
  • 找不到与'@style/Theme.Holo.NumberPicker'匹配的资源

标签: android numberpicker


【解决方案1】:

您使用的是Formatter 吗?我不得不使用setDisplayedValues 来解决这个问题。 我假设你已经解决了这个问题,但我还是发布了这个,我绝望地寻找答案,偶然解决了。

    NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(5);     
    String[] periodicityValues = {"Semanal", "Mensal", "Bimestral", "Trimestral", "Semestral", "Anual"};
    numberPicker.setDisplayedValues(periodicityValues);

【讨论】:

  • 这如何改变文本颜色?
  • 确切地说,它将如何改变文本颜色
【解决方案2】:

我知道这个问题很老了。我在这里找到了答案:Change the text color of 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-05-11
    • 1970-01-01
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 2014-01-24
    • 2016-09-30
    相关资源
    最近更新 更多