This is an example to demonstrate how we can add HTML in Android TextView using Java code,
- Add TextView to your Activity:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id = "@+id/htmlView" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
- Now lets check the Java Code: src/MainActivity.java
public class MainActivity extends AppCompatActivity { String htmlCodeText = "<p style="background:green">Hello, this a HTML code!</p>"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView htmlToTextView = findViewById(R.id.htmlView); htmlToTextView.setText(HtmlCompat.fromHtml(htmlCodeText, 0)); } }
More Posts related to Android,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- Word wrap text in Notepad++ - NotepadPlusPlus
- ls: .: Operation not permitted - Mac Big Sur Terminal Zsh Error - MacOS
- Android Images with Rounded Corners : ImageView - Android
- How to Download Jira App for Mac - Jira
- Android Disable back button programatically - Android
- How to enable Dark Mode in Windows 11 - Windows-11
- Check Bluetooth is turned on or off on Android device programmatically [Java Code] - Android
- How to know docker Engine details - Docker