DevEco Studio中警告"Hardcoded String ‘中文’, should use ‘$string:中文’ resourse"的解决方式
例如在xml文件中
<Button
ohos:id="$+id:gomoku_button"
ohos:width="200fp"
ohos:height="70fp"
ohos:text_size="27fp"
ohos:text="中文"//此处有警告
ohos:text_color="white"
ohos:background_element="$graphic:genre_background_button"
ohos:left_margin="5vp"
ohos:bottom_margin="25vp"
ohos:right_padding="8vp"
ohos:left_padding="8vp"
/>
解决方式:
在此路径下的string.json的"string"中新增
{
"string": [
...
{
"name": "zhongwen",
"value": "中文"
},
...
]
}
修改之前的代码为:
<Button
ohos:id="$+id:gomoku_button"
ohos:width="200fp"
ohos:height="70fp"
ohos:text_size="27fp"
ohos:text="$string:zhongwen"//修改后
ohos:text_color="white"
ohos:background_element="$graphic:genre_background_button"
ohos:left_margin="5vp"
ohos:bottom_margin="25vp"
ohos:right_padding="8vp"
ohos:left_padding="8vp"
/>