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

之前经常使用Spannable

这次主要在String.xml使用:

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

    <![CDATA[变色 曲项向天歌 白毛浮绿水]]>
    
    <![CDATA[变色、换行 曲项向天歌
白毛浮绿水]]> <![CDATA[斜体 曲项向天歌 白毛浮绿水]]> <![CDATA[下划线 曲项向天歌 白毛浮绿水]]> <![CDATA[下划线、变色 曲项向天歌 白毛浮绿水]]> <![CDATA[中划线 曲项向天歌 白毛浮绿水]]> <![CDATA[放大 曲项向天歌 白毛浮绿水]]> <![CDATA[缩小 曲项向天歌 白毛浮绿水]]> <!-- “ Hello, %1$s! You have <b>%2$d new messages</b> <!-- 内容放在里 %1$s 第一个要填充的字符串 %2$d 第二个要填充的int值-->

类里:

 

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

 

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/675750229b.html