I had to display some code in my textview with syntax highlighting. So i am testing if the syntax hhighligting works or not
I added some test code to my strings.xml and tried to display it in textview
Everything works good but when the app is run the code is being displayed in 1 line
Like below
My code
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">syntaxtest</string>
<string name="javacode">
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.mainTextView);
}
}</string>
mainactivity.java
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String code = getResources().getString(R.string.javacode);
TextView tv = (TextView) findViewById(R.id.mainTextView);
// code is a String with source code to highlight
// myTextView is a TextView component
PrettifyHighlighter highlighter = new PrettifyHighlighter();
String highlighted = highlighter.highlight("java", code);
tv.setText(Html.fromHtml(highlighted));
}
}