Skip to content

Commit 79c17c8

Browse files
committed
Added new method to assign you own typeface
1 parent 2f1fb56 commit 79c17c8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/main/java/com/github/stephenvinouze/materialnumberpickercore/MaterialNumberPicker.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class MaterialNumberPicker : NumberPicker {
6060
field = value
6161
updateTextAttributes()
6262
}
63+
private var fontNameTypeFace: Typeface? = null
64+
6365
private val inputEditText: EditText? by lazy {
6466
try {
6567
val f = NumberPicker::class.java.getDeclaredField("mInputText")
@@ -148,11 +150,19 @@ class MaterialNumberPicker : NumberPicker {
148150
inputEditText?.filters = arrayOfNulls(0)
149151
}
150152

153+
/**
154+
* Set the font name using your own typeface (example: if you have the font in the resources folder)
155+
*/
156+
private fun setFontName(typeface: Typeface) {
157+
fontNameTypeFace = typeface
158+
updateTextAttributes()
159+
}
160+
151161
/**
152162
* Uses reflection to access text size private attribute for both wheel and edit text inside the number picker.
153163
*/
154164
private fun updateTextAttributes() {
155-
val typeface = if (fontName != null)
165+
val typeface = fontNameTypeFace ?: if (fontName != null)
156166
Typeface.createFromAsset(context.assets, "fonts/$fontName")
157167
else
158168
Typeface.create(Typeface.DEFAULT, textStyle)

0 commit comments

Comments
 (0)