How change font type in NumberPicker. I try to do like this, but font not changing. Any idea? P.S: color and textSize are change.
public class NumberPicker extends android.widget.NumberPicker {
private Context context;
private Typeface tfs;
public NumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
tfs = Typeface.createFromAsset(context.getAssets(),"fonts/font.ttf");
}
@Override
public void addView(View child) {
super.addView(child);
updateView(child);
}
@Override
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateView(child);
}
@Override
public void addView(View child, android.view.ViewGroup.LayoutParams params) {
super.addView(child, params);
updateView(child);
}
private void updateView(View view) {
if(view instanceof EditText){
((EditText) view).setTypeface(tfs);
((EditText) view).setTextSize(25);
((EditText) view).setTextColor(Color.RED);
}
}
}
Font and path work correctly. I use it for my custom text views.
Add below style in your style.xml.
<style name="NumberPickerCustomText">
<item name="android:textSize">22sp</item> // add if you want to change size
<item name="android:fontFamily">@font/lato_regular</item> // add font (this font folder is present in res folder)
</style>
Directly add this style to your Number Picker in XML.
android:theme="@style/NumberPickerCustomText"