Kotlin Styling TextView Programmatically (KSTP)

Is there a way to programmatically set the textStyle attribute of a TextView? There doesn't seem to be a setTextStyle() method. Let's say I have the following basic TextView, and I want to style it in native kotlin code, is there a way to do that? 

<TextView
  android:id= "@+id/my_text" 
  android:layout_width= "fill_parent" 
  android:layout_height= "wrap_content" 
  android:text= "Hello World" 
  android:textStyle= "bold" />

Solution

Instead you need to use  setTypeface()

textview.setTypeface(textview.getTypeface(), Typeface.BOLD)

Post a Comment

Previous Next

نموذج الاتصال