NumberPicker textColour [英] NumberPicker textColour
问题描述
我有一个的ListView
包含的TextView
和 NumberPicker
每一行。
每当我开始了活动,的号码 NumberPicker
是白色的(相同的颜色作为背景)。
我试过应用样式的建议这里,的这里和<一个href=\"http://stackoverflow.com/questions/13882707/need-help-by-creating-a-dialog-with-2-numberpickers\">here ;无济于事。
任何其他建议?
-
NumberPicker.xml
&LT; NumberPicker
机器人:ID =@ + ID / npMaterialAmount
机器人:layout_alignParentRight =真
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =75dp
风格=@风格/ npColour/&GT;
-
试过的风格1:
&LT;样式名称=npColour&GT;
&LT;项目名称=机器人:文字颜色&GT;#000000&LT; /项目&GT;
&LT; /风格&GT;
-
试过的风格2:
&LT;样式名称=npColour父=@安卓风格/ Theme.Holo.Light&GT;
&LT; /风格&GT;
-
...和这样的例子不胜枚举...
我知道这个问题是旧的。我在这里创办了答案:更改NumberPicker 的文本颜色
复制:
这code应该解决您的问题。您所遇到的问题是因为NumberPicker施工期间,它捕获的EditText文字颜色和分配到油漆,因此可以得出上面和下面搭配同色系编辑文本的数字。
块引用>进口java.lang.reflect.Field中;公共静态布尔setNumberPickerTextColor(NumberPicker numberPicker,诠释颜色)
{
最终诠释计数= numberPicker.getChildCount();
的for(int i = 0; I&LT;计数;我++){
查看孩子= numberPicker.getChildAt(I)
如果(孩子的instanceof的EditText){
尝试{
现场selectorWheelPaintField = numberPicker.getClass()
.getDeclaredField(mSelectorWheelPaint);
selectorWheelPaintField.setAccessible(真);
((油漆)selectorWheelPaintField.get(numberPicker))的setColor(彩色)。
((EditText上)子).setTextColor(彩色);
numberPicker.invalidate();
返回true;
}
赶上(NoSuchFieldException E){
Log.w(setNumberPickerTextColor,E);
}
赶上(IllegalAccessException E){
Log.w(setNumberPickerTextColor,E);
}
赶上(抛出:IllegalArgumentException五){
Log.w(setNumberPickerTextColor,E);
}
}
}
返回false;
}I have a
ListView
containing aTextView
and aNumberPicker
for each row. Whenever I start up the activity, the numbers of theNumberPicker
are white (the same color as the background).I tried applying a style as suggested here, here, and here ; to no avail.
Any other suggestions?
-
NumberPicker.xml
<NumberPicker android:id="@+id/npMaterialAmount" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="75dp" style="@style/npColour"/>
-
Tried style 1:
<style name = "npColour" > <item name = "android:textColor">#000000</item> </style>
-
Tried style 2:
<style name = "npColour" parent ="@android:style/Theme.Holo.Light"> </style>
-
... and the list goes on...
解决方案I know the question is old. I founded the answer here: Change the text color of NumberPicker
Copy:
This code should solve your problem. The problem you are experiencing is because during the construction of NumberPicker it captures the EditText textColor and assigns to to a paint so it can draw the numbers above and below the edit text with the same color.
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; }
这篇关于NumberPicker textColour的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!