android - How can I change the fonts in android using Kotlin?
问题描述
I am try change the font, but not working. Are returning "null" being that I set the value in the XML and also in the code.
Kotlin Code
val typeFace = Typeface.createFromAsset(tvThanks.context.assets, "dinpro_medium.ttf")
tvThanks.setTypeface(typeFace)
<TextView
android:id="@+id/tvThanks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_here"/>
ERROR
java.lang.IllegalStateException: tvThanks must not be null
at br.com.adrianofpinheiro.testesantander.fragment.ContatoEnviadoFragment.onCreate(ContatoEnviadoFragment.kt:21)
解决方案
Your fragment should have the context
property without getting from the tvThanks
.
I think you can try doing this inside the onCreateView
of your fragment
val typeFace = Typeface.createFromAsset(context.assets, "dinpro_medium.ttf")
tvThanks!!.setTypeface(typeFace)
推荐阅读
- r - 在 model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) 中不断出现错误:因子 subj 有新的水平
- variables - 如何在汇编中将 Int 转换为 String
- mysql - Mysql删除带下划线的变量
- php - PHP 会话数据在 https 中丢失
- c# - 高效地对大量数据进行排序
- ionic-framework - 我正在尝试在 IonSelect multiple 中添加值,但它在反应离子中仅选择一个值
- c# - Unity - 错误构建播放器,因为脚本在编辑器中有编译错误
- jquery - 邮递员发布请求给出正确的结果,但 ajax 发布给出 Count=0
- reactjs - ColumnsDirective 的列值在动态添加列时未显示
- ruby-on-rails - Rails 邮件程序未发送