Displaying html string preview in the Layout Editor

253 Views Asked by At

I have this html string in the strings.xml file in my Android project

Registrandoti confermi di accettare i
        <a href="https://www.google.com/">
            <font color="#FF7860">Termini del Servizio</font>
        </a>
        e
        <a href="https://www.google.com/">
            <font color="#FF7860">l\'Informativa sulla privacy.</font>
        </a>

The string is displayed within a TextView in my layout file as below:

 <TextView android:layout_width="0dp" android:layout_height="wrap_content"
                  android:text="@string/registration_disclaimer"
                  android:id="@+id/tvRegistrationDisclaimer"
                  android:gravity="center"
                  app:layout_constraintTop_toBottomOf="@+id/button" app:layout_constraintStart_toStartOf="@+id/button"
                  android:layout_marginTop="16dp" app:layout_constraintEnd_toEndOf="@+id/button"/>

I was wondering if Android Studio allows to show the string in the layout with the right preview (showing font colors and links), something like tools:isHtml = true. Unfortunately I can't find anything from the official "tools" documentation. Is there any workaround?

1

There are 1 best solutions below

0
Parham On

I don't think that it's supported in preview however you can try this in yourClass.java: yourTextView.setText(Html.fromHtml("string with html format here", Html.FROM_HTML_MODE_COMPACT));