Last active
July 28, 2022 16:21
-
-
Save fulcrum6378/344c9c20598bdbeccb631902c74733ba to your computer and use it in GitHub Desktop.
Customised NumberPicker capable of applying a font resource on its numbers. (it was quite difficult to discover this hack tho!!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package <COM.MY.APPLICATION> | |
import android.content.Context | |
import android.util.AttributeSet | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.EditText | |
import android.widget.NumberPicker | |
class PrettyNumberPicker( | |
context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int | |
) : NumberPicker(context, attrs, defStyleAttr, defStyleRes) { | |
constructor(context: Context) : this(context, null) | |
constructor(context: Context, attrs: AttributeSet?) : | |
this(context, attrs, android.R.attr.numberPickerStyle) | |
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : | |
this(context, attrs, defStyleAttr, 0) | |
override fun addView(child: View?, params: ViewGroup.LayoutParams?) { | |
super.addView(child, params) | |
if (child is EditText) { | |
child.typeface = context.resources.getFont(<YOUR FONT RESOURCE ID HERE>) | |
child.isEnabled = false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment