Android 为什么';在设备屏幕上显示时,我的文本不能为粗体
Mystring.xml:Android 为什么';在设备屏幕上显示时,我的文本不能为粗体,android,android-layout,android-emulator,Android,Android Layout,Android Emulator,Mystring.xml: <!--I try to bold my argument %s, like below:--> <string name="hello">Hello to: <b>%s</b> !</string> <LinearLayout ...> <TextView android:id="@+id/hello_txt" ... .../> </
<!--I try to bold my argument %s, like below:-->
<string name="hello">Hello to: <b>%s</b> !</string>
<LinearLayout
...>
<TextView
android:id="@+id/hello_txt"
...
.../>
</LinearLayout>
当我在我的设备上运行我的应用程序时,屏幕上显示了“Hello to:Monday!”,但是“Monday”不是粗体的,而是我在string.xml中使用了
。为什么不加粗???使用Html.fromHTML()方法
使用Html.fromHTML()方法
如果您使用的是
html
标记,则需要使用html.fromHtml
,如下所示:
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
String styledText=“这很简单。”;
textView.setText(Html.fromHtml(styledText),textView.BufferType.SPANNABLE);
如果您使用的是html
标记,那么您需要使用html.fromHtml
,如下所示:
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
String styledText=“这很简单。”;
textView.setText(Html.fromHtml(styledText),textView.BufferType.SPANNABLE);
试试这个:
String.xml:
<string name="hello">Hello to: <b>%s</b>.</string>
它对我有用
希望对你有帮助
谢谢。试试这个:
String.xml:
<string name="hello">Hello to: <b>%s</b>.</string>
它对我有用
希望对你有帮助
谢谢。Aha!,诀窍是“”而不是“啊哈!”,诀窍是“”而不是“
TextView mytext1 = (TextView) findViewById(R.id.tx1);
mytext1.setText(Html.fromHtml(String.format(getString(R.string.hello), "Monday")));