![](/img/trans.png)
[英]Android - can I increase the textSize for the NumberPicker widget?
[英]Change NumberPicker TextSize
如何設置數字選擇器的中心選擇值的文本大小? 並且當滾動時,中心號碼的大小應該大於其他號碼。
我嘗試使用以下代碼:
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);
((EditText) child).setTextSize(48);
numberPicker.invalidate();
return true;
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
Log.w("setNumberPickerTextColor", e);
}
}
}
return false;
}
但滾動后文本大小恢復正常
你可以使用XML和樣式的力量來做到這一點。
首先將以下內容添加到styles.xml
<style name="MyTheme.NumberPicker">
<item name="android:textSize">11dp</item>
</style>
然后在NumberPicker
使用該樣式,如下所示:
<android.widget.NumberPicker
...
android:theme="@style/MyTheme.NumberPicker"
.../>
測試API +17
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.