简体   繁体   English

在TextView中使用不同的字体样式

[英]Using Different Font Styles in TextView

I can display the contents of a file in a TextView by adding the file under the raw folder and reading the file. 我可以通过在raw文件夹下添加文件并读取文件来在TextView显示文件的内容。 It works fine. 它工作正常。 But all of the contents in the file look the same. 但是文件中的所有内容看起来都一样。 I want to differentiate titles and the contents by introducing Font styles. 我想通过引入字体样式来区分标题和内容。 Can anybody help? 有人可以帮忙吗?

What I understood from your question is that you want to apply different formatting to different parts of your text in TextView. 我从您的问题中理解的是,您希望在TextView中将不同的格式应用于文本的不同部分。 But As I know, TextView doesn't supports multiple styles (formatting) (yet). 但据我所知,TextView不支持多种样式(格式化)(尚未)。 Whatever the formatting you apply, will be applied to the whole text in TextView. 无论您应用何种格式,都将应用于TextView中的整个文本。 To use different formatting, you can use the WebView . 要使用不同的格式,可以使用WebView

Update: 更新:

This functionality is available for EditText (I saw it too late), see this link for details; 这个功能可用于EditText(我看得太晚了),详见此链接; http://developer.android.com/resources/faq/commontasks.html#selectingtext http://developer.android.com/resources/faq/commontasks.html#selectingtext

You can use WebView instead as your text is static you can format it to create a htmlPage and then display it in webview something like this 您可以使用WebView因为您的文本是静态的,您可以格式化它以创建htmlPage然后在webview显示它像这样

WebView mView = (WebView) findViewById(R.id.help_text);
mView.loadUrl("file:///android_asset/help.html");
mView.getSettings().setSupportZoom(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM