0
点赞
收藏
分享

微信扫一扫

Do not concatenate text displayed with setText,use resource string with placeholders.

警告大意:

应该使用资源字符串来显示文本占位符

与在xml布局中直接写汉字的警告是一个意思

字符串拼接也好,直接写的汉字也好,

都应该在strings.xml文件中声明,然后引用


for example:

layout.xml文件引用

Do not concatenate text displayed with setText,use resource string with placeholders._resource string

strings.xml文件中声明

Do not concatenate text displayed with setText,use resource string with placeholders._字符串_02



关于变量拼接参数


比如:


mTextView.setText("距离过年还有"+mDay+"天"+mMinute+"时"+mSecond+"秒");

声明:


<string name="delay_time">距离过年还有%1$d天%2$d时%3$d秒</string>

在代码中的使用:


mTextView.setText(String.format(getResources().getString(R.string.delay_time),mDay,mMinute,mSecond));

声明在前,参数在后

常用格式:


%n$s--->n表示目前是第几个参数 (比如%1$s中的1代表第一个参数),s代表字符串


%n$d--->n表示目前是第几个参数 (比如%1$d中的1代表第一个参数),d代表整数


%n$f--->n表示目前是第几个参数 (比如%1$f中的1代表第一个参数),f代表浮点数




举报

相关推荐

0 条评论