How to display HTML in TextView?

You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work. This is what you should do in Java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { textView.setText(Html.fromHtml(“<h2>Title</h2><br><p>Description here</p>”, Html.FROM_HTML_MODE_COMPACT)); } else { textView.setText(Html.fromHtml(“<h2>Title</h2><br><p>Description here</p>”)); } And in Kotlin: textView.text = if (Build.VERSION.SDK_INT >= … Read more

How do I center text horizontally and vertically in a TextView?

I’m assuming you’re using XML layout. <TextView android:layout_width=”match_parent” android:layout_height=”match_parent” android:gravity=”center” android:text=”@string/**yourtextstring**” /> You can also use gravity center_vertical or center_horizontal according to your need. As @stealthcopter commented, in java: .setGravity(Gravity.CENTER);. And for Kotlin users, .gravity = Gravity.CENTER