Android 如何在html段落中添加@string?

Android 如何在html段落中添加@string?,android,html,textview,Android,Html,Textview,我试图将@string/string\b放入html中。比如说, <string name="string_a">very long text</string> <string name="string_b"> <![CDATA[ <body> <p>This is string B</p> <p>@string/string_a&

我试图将
@string/string\b
放入html
中。比如说,

<string name="string_a">very long text</string>

<string name="string_b">
     <![CDATA[
        <body>
            <p>This is string B</p>
            <p>@string/string_a</p>
            <p>Another string here</p>
        </body>
    ]]>
</string>
非常长的文本
这是字符串B

@字符串/字符串a

这里还有一根绳子

]]>
这将仅显示:
这是字符串B
@字符串/string_a
这里还有一根绳子

但我想展示:
这是字符串B
非常长的文本。
这里还有一根绳子


顺便说一句,它将显示在中。如果可以的话,我只想把它放在xml内部。谢谢你们

strings.xml中进行此更改:

 <string name="string_b">
         <![CDATA[
            <body>
                <p>This is string B</p>
                <p>%1$s</p>
                <p>Another string here</p>
            </body>
        ]]>
    </string>

在您要求仅在xml中执行此操作时,我发现它引用了相同的内容。因此,您可以查看这里给出的答案,看看它是否适合您。

这是我的答案。希望它能帮助别人。扩展
HtmlTextView
使我们有机会使用
string
格式添加新属性。然后,
android:text
custom:text2
可以在custom
HtmlTextView
中通过编程连接

1。扩展HtmlTextView 或者,如果您正在使用文本视图

public class HtmlTextview extends HtmlTextView {
    public HtmlTextview(Context context) {
        super(context);
    }

    public HtmlTextview(Context context, AttributeSet attrs) {
        super(context, attrs);
        setupText(attrs);
    }

    public HtmlTextview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setupText(attrs);
    }

    private void setupText(AttributeSet attrs) {

        String htmlString = (String) this.getText();
        String text2;

        TypedArray attributeValuesArray = getContext().obtainStyledAttributes(attrs, R.styleable.concatenate, 0, 0);
        try{
            text2 = attributeValuesArray.getString(R.styleable.concatenate_text2);
        } finally {
            attributeValuesArray.recycle();
        }

        if(text2 != null && text2.length() > 0){
            htmlString = htmlString + text2;
            this.setHtmlFromString(htmlString, new HtmlTextView.RemoteImageGetter());
        }
    }
}
2。HtmlTextview属性

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <declare-styleable name="concatenate">
        <attr name="text2" format="string"/>
    </declare-styleable>

</resources>
<resources>
    <string name="app_name">HtmlTry</string>

    <string name="string_a">
        <![CDATA[
        <body>
            <p>very long text. Can also formatted in <font color="#f44336">Html.</font></p>
        </body>
        ]]>
    </string>

    <string name="string_b">
        <![CDATA[
        <body>
            <p>This is string B</p>
        </body>
        ]]>
    </string>

</resources>


是否可以只使用xml格式?请查看我在编辑中链接的问题和答案。您是否成功地使用了xml格式?是的,但使用了另一种方式。通过扩展HtmlTextView。顺便说一句,谢谢。没问题,你自己发布你的答案,这样如果其他人有同样的问题,他们可以看到解决方案。
<resources>
    <string name="app_name">HtmlTry</string>

    <string name="string_a">
        <![CDATA[
        <body>
            <p>very long text. Can also formatted in <font color="#f44336">Html.</font></p>
        </body>
        ]]>
    </string>

    <string name="string_b">
        <![CDATA[
        <body>
            <p>This is string B</p>
        </body>
        ]]>
    </string>

</resources>
<com.htmltry.HtmlTextview
   android:id="@+id/tv"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/string_b"
   custom:text2="@string/string_a"
/>