I found this tutorial. You can use HTML and CSS with TextView without using WebView, but you should use Html.fromHtmlas below, and useSpanned
Give it a try!
Android Spannable Info See here
public class MainActivity extends ActionBarActivity {
private TextView textView;
private final String htmlWithCSS = "<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
"<style>\n" +
"a1 {\n" +
" text-decoration: overline;\n" +
"}\n" +
"\n" +
"a2 {\n" +
" text-decoration: line-through;\n" +
"}\n" +
"\n" +
"a3 {\n" +
" text-decoration: underline;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
"\n" +
"<a1>This is heading 1</a1>\n" +
"<a2>This is heading 2</a2>\n" +
"<a3>This is heading 3</a3>\n" +
"\n" +
"</body>\n" +
"</html>\n";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = ((CustomTextView) findViewById(R.id.text_view));
Spanned spanned = Html.fromHtml(htmlWithCSS);
textView.setText(spanned);
}
}
source
share