aabhasr1 / OtpView

A custom view to enter otp/pin of different sizes used usually in cases of authentication.
MIT License
377 stars 99 forks source link

how to change font in otpView #26

Closed nashihu closed 3 years ago

nashihu commented 3 years ago

hello, thanks for your great library

i would like to ask, how do i change font in otpView? i see there's attribute called app:text_typeface, but i dont know how to use it programmatically / directly from xml..

thank you

nashihu commented 3 years ago

i just check the code

val otpTextTypeFace = styles.getString(R.styleable.text_typeface)
...
if (otpTextTypeFace != null) {
            try {
                val tf = Typeface.createFromAsset(context.assets, otpTextTypeFace)
                textView?.typeface = tf
            } catch (e: Exception) {
                e.printStackTrace()
            }

        }

so the answer is basicly put your font into assets folder, and then set app:text_typeface="YourFont.tff"

then it works.

thanks

ecemsuren commented 3 years ago

I did it like this but didn't work for me. Is there any solution to solve this? thank you

nashihu commented 3 years ago

@ecemsuren i guess your problem caused by reference failure. can you please share your xml and font path?

ecemsuren commented 3 years ago

@nashihu I understood my problem after 5 hours. I did not add my font to the asset folder. Later, I reread what you wrote. It did when I added it to the Asset folder. Thank you very much for your comment. I probably would never have done it without your comment.