[英]Adding HTML tags into text
In main page of my program I have some buttons such as Help. 在程序的主页上,有一些按钮,例如“帮助”。 When user clicks it an activity appears and shows some guideline. 当用户单击它时,将显示一个活动并显示一些准则。 It is full text and I need to change color of some words as I like. 它是全文,我需要根据需要更改某些单词的颜色。 for bold and italic I don't have problem, easily I surround my words with 对于粗体和斜体我没有问题,很容易我用 . 。 But I don't know what should I do to change color of some words. 但是我不知道该如何更改某些单词的颜色。
Please tell me what should I do? 请告诉我该怎么办?
How about using a WebView instead of a TextView, then you can just update the HTML. 如何使用WebView代替TextView,然后可以只更新HTML。 It is definitely uses more resources, but may do what you need. 它肯定会使用更多的资源,但可以满足您的需要。
Use Html.fromHtml
to create a Spanned
text and assign it to the TextView. 使用Html.fromHtml
创建Spanned
文本,并将其分配给TextView的。
http://developer.android.com/reference/android/text/Html.html http://developer.android.com/reference/android/text/Html.html
I thought that you want to provide About us/Help file inside your android application , then you can perform as the following: 我认为您想在android应用程序中提供关于我们/帮助文件 ,那么您可以执行以下操作:
webview.loadUrl("file:///android_asset/about_applicatio.html"); webview.loadUrl( “文件:///android_asset/about_applicatio.html”);
This way you can create a HTML file and thereby you can apply the color/javascript/bold/italic that you want inside the HTML file. 这样,您可以创建HTML文件,从而可以在HTML文件中应用所需的颜色/ javascript /粗体/斜体 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.