Android: html in strings.xml

后端 未结 5 1940
谎友^
谎友^ 2020-11-29 21:10

I would like display for example this html code:


    

Hello World

This is a test of the URL &

5条回答
  •  粉色の甜心
    2020-11-29 22:00

    String.xml can contains HTML entities, like so:

    
        <span>
    
    

    In your code: getResources().getString(R.string.hello_world); will evaluate to "". You can use this HTML formatted text like this:

    TextView helloWorld = (TextView)findViewById(R.id.hello_world);
    helloWorld.setText(Html.fromHtml(getString(R.string.hello_world)));
    

提交回复
热议问题