Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么';在设备屏幕上显示时,我的文本不能为粗体_Android_Android Layout_Android Emulator - Fatal编程技术网

Android 为什么';在设备屏幕上显示时,我的文本不能为粗体

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" ... .../> </

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"
     ...
     .../>

</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:  &lt;b>%s&lt;/b>.</string>
它对我有用

希望对你有帮助

谢谢。

试试这个:

String.xml:

<string name="hello">Hello to:  &lt;b>%s&lt;/b>.</string>
它对我有用

希望对你有帮助

谢谢。

Aha!,诀窍是“”而不是“啊哈!”,诀窍是“”而不是“
TextView mytext1 = (TextView) findViewById(R.id.tx1);
mytext1.setText(Html.fromHtml(String.format(getString(R.string.hello), "Monday")));