-1

everyone.

[What I'd like to do]

To display source code "prettily" in android app. Like this. enter image description here
At least if there are indents, it's fine.

[Why?]

Because I'm developing an android app where users can see Views and its source code at the same time.

[Issue]

Showing source codes on TextView looks ugly. A lot of escape characters needed for <> and the text layout collapsed. Googling and searching on Stackoverflow didn't give me any useful information.

Any help would be appreciated. Thanks!

(update 2015/11/23)
These link might be useful when you use WebView to display source codes.
- How can I display HTML source code within a HTML website? [duplicate]
- How to display source code with indent in a web page? HTML? CSS?

Community
  • 1
  • 1
dixhom
  • 2,419
  • 4
  • 20
  • 36
  • Do you have html content of your code with all these properties set? If yes, why not show them in webView? – DGN Nov 23 '15 at 07:56
  • WebView! I should have come up with it. Thanks. But I still have to escape characters... other solutions are welcome. – dixhom Nov 23 '15 at 08:04

2 Answers2

1

I think this question is a tricky one. I tried to google myself and only find this library https://android-arsenal.com/details/1/2049 which supports different text appearence. Hope this will help you out.

RexSplode
  • 1,475
  • 1
  • 16
  • 24
1

Displaying the text in a WebView is a great idea as you can now use javascript APIs like Google's Code Prettify I believe SO uses it ;)

The comments in prettify.js are authoritative but the lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, Makefiles, and Rust.

It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and Ruby, but, because of commenting conventions, doesn't work on Smalltalk, OCaml, etc. without a language extension.

Other languages are supported via extensions:

Apollo; Basic; Clojure; CSS; Dart; Erlang; Go; Haskell; Lasso; Lisp, Scheme; Llvm; Logtalk; Lua; Matlab; MLs: F#, Ocaml,SML; Mumps; Nemerle; Pascal; Protocol buffers; R, S; RD; Rust; Scala; SQL; Swift; TCL; Latek; Visual Basic; VHDL; Wiki; XQ; YAML

Gusdor
  • 14,001
  • 2
  • 52
  • 64
  • This looks great! A sad thing is that internet connection is requred for this. But thanks for this. – dixhom Nov 23 '15 at 08:19
  • @dixhom I'm not convinced about that. The full source is available on github and you should be able to embed it locally. – Gusdor Nov 23 '15 at 08:43