之前經(jīng)常使用Spannable
這次主要在String.xml使用:<![CDATA[和]]>
效果:
<resources>
<string name="str_bianse"><![CDATA[變色 <font color="#ff0000">曲項(xiàng)向天歌</font> 白毛浮綠水]]></string>
<string name="str_jiacu"><![CDATA[加粗1 <b>曲項(xiàng)向天歌</b> 白毛浮綠水]]></string>
<string name="str_huanhang"><![CDATA[變色、換行 <font color="#ff0000">曲項(xiàng)向天歌</font><br> 白毛浮綠水]]></string>
<string name="str_xieti"><![CDATA[斜體 <i><font>曲項(xiàng)向天歌</font></i> 白毛浮綠水]]></string>
<string name="str_xiahuaxian"><![CDATA[下劃線 <u>曲項(xiàng)向天歌</u> 白毛浮綠水]]></string>
<string name="str_xiahuaxian_bianse"><![CDATA[下劃線、變色 <u><font color="#ff0000">曲項(xiàng)向天歌</font></u> 白毛浮綠水]]></string>
<string name="str_zhonghuaxian"><![CDATA[中劃線 <s>曲項(xiàng)向天歌</s> 白毛浮綠水]]></string>
<string name="str_jiacu2"><![CDATA[加粗2 <strong>曲項(xiàng)向天歌</strong> 白毛浮綠水]]></string>
<string name="str_fangda"><![CDATA[放大 <big>曲項(xiàng)向天歌</big> 白毛浮綠水]]></string>
<string name="str_souxiao"><![CDATA[縮小 <small>曲項(xiàng)向天歌</small> 白毛浮綠水]]></string>
<!-- “<”改成HTML轉(zhuǎn)義符<-->
<string name="welcome_messages">Hello, %1$s! You have <b>%2$d new messages</b></string>
<!-- 內(nèi)容放在<![CDATA[和]]>里 %1$s 第一個要填充的字符串 %2$d 第二個要填充的int值-->
<string name="welcome_messages2"><![CDATA[Hello, %1$s! You have <b>%2$d new messages</b>]]></string>
</resources>
類里:
?文章來源:http://www.zghlxwxcb.cn/news/detail-786868.html
TextView second_1_Tv = findViewById(R.id.second_1_Tv);
second_1_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_bianse)));
TextView second_2_Tv = findViewById(R.id.second_2_Tv);
second_2_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_jiacu)));
TextView second_3_Tv = findViewById(R.id.second_3_Tv);
second_3_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_huanhang)));
TextView second_4_Tv = findViewById(R.id.second_4_Tv);
second_4_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_xieti)));
TextView second_5_Tv = findViewById(R.id.second_5_Tv);
second_5_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_xiahuaxian)));
TextView second_6_Tv = findViewById(R.id.second_6_Tv);
second_6_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_xiahuaxian_bianse)));
TextView second_7_Tv = findViewById(R.id.second_7_Tv);
second_7_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_zhonghuaxian)));
TextView second_8_Tv = findViewById(R.id.second_8_Tv);
second_8_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_jiacu2)));
TextView second_9_Tv = findViewById(R.id.second_9_Tv);
second_9_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_fangda)));
TextView second_10_Tv = findViewById(R.id.second_10_Tv);
second_10_Tv.setText(Html.fromHtml(getResources().getString(R.string.str_souxiao)));
TextView second_12_Tv = findViewById(R.id.second_12_Tv);
String text = String.format(getResources().getString(R.string.welcome_messages), "大呲花", 666);
second_12_Tv.setText(Html.fromHtml(text));
TextView second_14_Tv = findViewById(R.id.second_14_Tv);
Spanned spanned = Html.fromHtml(getResources().getString(R.string.welcome_messages2, "大呲花", 666));
second_14_Tv.setText(spanned);
?文章來源地址http://www.zghlxwxcb.cn/news/detail-786868.html
到了這里,關(guān)于Android String.xml 設(shè)置加粗字體/修改字體顏色/動態(tài)設(shè)置修改文案的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!