Change font Textview

Asked

Viewed 174 times

1

I am having problems changing the source of Textview in my project, I have tried all methods found on the internet and none altered. No debug errors and no errors when opening the app.
I’m using the Kotlin language.

Information

compileSdkVersion 29
buildToolsVersion "29.0.2"
minSdkVersion 15

My first attempt was to create a repository font and put the source inside the same, then change the android:fontFamily="@font/customfont". Unsuccessful.

Second attempt was to use programming along with Assets/fonts/customfont.ttf

textLogo.typeface = Typeface.createFromAsset(assets, "fonts/customfont.ttf")

Unsuccessful too. I don’t know what else to do.
Another source works normally.

When opening the file .ttf the following error occurs from the source. inserir a descrição da imagem aqui

With this Exception

java.lang.IllegalArgumentException: TextHitInfo is out of range
at java.awt.font.TextLayout.checkTextHit(TextLayout.java:780)
at java.awt.font.TextLayout.getCaretInfo(TextLayout.java:1220)
at java.awt.font.TextLayout.getCaretInfo(TextLayout.java:1322)
at javax.swing.text.GlyphPainter2.getSpan(GlyphPainter2.java:82)
at javax.swing.text.GlyphView.getPartialSpan(GlyphView.java:330)
at javax.swing.text.GlyphView.getMinimumSpan(GlyphView.java:557)
at javax.swing.text.ParagraphView.calculateMinorAxisRequirements(ParagraphView.java:725)
at javax.swing.plaf.basic.BasicTextAreaUI$PlainParagraph.calculateMinorAxisRequirements(BasicTextAreaUI.java:272)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:568)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:903)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:343)
at javax.swing.text.BoxView.layout(BoxView.java:708)
at javax.swing.text.BoxView.setSize(BoxView.java:397)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1769)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1072)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1050)
at javax.swing.text.DefaultCaret.repaintNewCaret(DefaultCaret.java:1308)
at javax.swing.text.DefaultCaret$1.run(DefaultCaret.java:1287)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:757)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:706)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:375)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

1 answer

1

Always post the code. How are you trying? Something like this would solve:

val textView: TextView = findViewById(Rep.id.android_text) as TextView
textView.setOnClickListener {
textView.text = getString(Rep.string.name)
}
  • I’m just trying to change the font, but the font I liked is showing errors. Other fonts work I don’t know why. With another source it solved app:fontFamily="@font/modernia, but with the source I liked nothing solves.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.