Cuo*_*Huy 0 android getstring textview settext
我想通过setText()显示粗体文本,但是我只是看到文本不是粗体:(我该如何解决这个问题?
这是我的代码:String.xml:
<string name="country"><b>AMERICA-default</b></string>
Run Code Online (Sandbox Code Playgroud)
我的Java代码:
Resources resources;
TextView tvCountry;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("test","onCreate()-second Activity");
setContentView(R.layout.activity_second);
resources = getResources();
tvCountry = (TextView) findViewById(R.id.tvCountry);
tvCountry.setText(resources.getString(R.string.country));//its not working !Text is not bold!
//CANNOT USE : tvCountry.setText(R.string.country);
}
Run Code Online (Sandbox Code Playgroud)
Replace < with < country value
<string name="country"><b>AMERICA-default</b></string>
Run Code Online (Sandbox Code Playgroud)
使用支持html标记的Html.fromHtml()设置资源字符串。
tvCountry.setText(Html.fromHtml(getResources().getString(R.string.country)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1085 次 |
| 最近记录: |