Android String.xml 设置加粗字体/修改字体颜色/动态设置修改文案

之前经常使用Spannable
这次主要在String.xml使用:<![CDATA[和]]>


效果:

<resources>
    <string name="str_bianse"><![CDATA[变色 <font color="#ff0000">曲项向天歌</font> 白毛浮绿水]]></string>
    <string name="str_jiacu"><![CDATA[加粗1 <b>曲项向天歌</b> 白毛浮绿水]]></string>
    <string name="str_huanhang"><![CDATA[变色、换行 <font color="#ff0000">曲项向天歌</font><br> 白毛浮绿水]]></string>
    <string name="str_xieti"><![CDATA[斜体 <i><font>曲项向天歌</font></i> 白毛浮绿水]]></string>
    <string name="str_xiahuaxian"><![CDATA[下划线 <u>曲项向天歌</u> 白毛浮绿水]]></string>
    <string name="str_xiahuaxian_bianse"><![CDATA[下划线、变色 <u><font color="#ff0000">曲项向天歌</font></u> 白毛浮绿水]]></string>
    <string name="str_zhonghuaxian"><![CDATA[中划线 <s>曲项向天歌</s> 白毛浮绿水]]></string>
    <string name="str_jiacu2"><![CDATA[加粗2 <strong>曲项向天歌</strong> 白毛浮绿水]]></string>
    <string name="str_fangda"><![CDATA[放大 <big>曲项向天歌</big> 白毛浮绿水]]></string>
    <string name="str_souxiao"><![CDATA[缩小 <small>曲项向天歌</small> 白毛浮绿水]]></string>
    <!--    “<”改成HTML转义符&lt-->
    <string name="welcome_messages">Hello, %1$s! You have &lt;b>%2$d new messages&lt;/b></string>
    <!--    内容放在<![CDATA[和]]>里   %1$s 第一个要填充的字符串 %2$d 第二个要填充的int值-->
    <string name="welcome_messages2"><![CDATA[Hello, %1$s! You have <b>%2$d new messages</b>]]></string>
</resources>

类里:
 

        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);


 

相关推荐

  1. Qt设置字体、下划线、斜体、字号,字体

    2023-12-06 11:14:02       29 阅读
  2. html中字体

    2023-12-06 11:14:02       15 阅读
  3. 小程序中修改input的placeholder字体颜色样式

    2023-12-06 11:14:02       32 阅读
  4. LaTex字体的方法

    2023-12-06 11:14:02       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-06 11:14:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-06 11:14:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-06 11:14:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-06 11:14:02       18 阅读

热门阅读

  1. 什么是供应链金融分账系统?

    2023-12-06 11:14:02       36 阅读
  2. vue2和vue3的区别

    2023-12-06 11:14:02       32 阅读
  3. oracle给用户授权查询权限

    2023-12-06 11:14:02       41 阅读
  4. MISRA C++ 2008 标准解析

    2023-12-06 11:14:02       35 阅读
  5. MX6ULL学习笔记(四)设备树的 OF 函数

    2023-12-06 11:14:02       29 阅读
  6. 函数式编程

    2023-12-06 11:14:02       37 阅读
  7. 关于打印机直连的分享

    2023-12-06 11:14:02       41 阅读