Katedral Pillon
Katedral Pillon

Reputation: 14864

SyntaxHighlighter for android TextView

I am looking for a SynctaxHighlighter for android TextView. I have experience using SyntaxHighlighters for Html files and I am showing such an example below. I am not including the js, jquery and css files necessary to make the Html work:

<pre class='brush:java'> blah blah </pre>

Upvotes: 0

Views: 161

Answers (2)

Rehan Sarwar
Rehan Sarwar

Reputation: 1004

I solve my problem by using this API for text highlighting which can solve my problem.

https://github.com/nakshay/TextHighlighter

This API allows you to pass words and colours specific to words and will return the string which is formatted with html tags which you can send to Html.fromHtml() to get highlighted text. Add below Gradle dependency to your module's gradle file.

compile 'com.github.akshay-naik:texthighlighterapi:1.2.1'

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006724

Off the cuff...

Option #1: Replace <pre> with <tt> and replace the classes+stylesheets with <font color="">, then use Html.fromHtml(). Or, have the whole TextView use monospace, and then you only need to worry about the <font color=""> part.

Option #2: Create your own Spanned object with a bunch of ForegroundColorSpan objects for the syntax highlighting.

Upvotes: 1

Related Questions