全部,我自定义一个城市选择器,里面用了三个numberPicker,像这样:
中国省市区域选择器。
代码:
String[] areas = get_from_somewhere();
areaPicker.setDisplayedValues(areas);
我想减小字体大小,有什么建议吗?
解决方案:Refer to this
最佳答案
为此,您可以在自定义类 CustomNumberPicker
中扩展默认的 NumberPicker
:
public class CustomNumberPicker extends NumberPicker {
public NumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void addView(View child) {
super.addView(child);
if(child instanceof EditText) {
((EditText) child).setTextSize(25);
}
}
}
现在将 xml 中的当前 NumberPicker
替换为 CustomNumberPicker
:
<com.pkg.name.CustomNumberPicker
android:id="@+id/number_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
关于android - 如何减小 NumberPicker 中的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26503548/