Java 如何处理文本视图中的2链接单击使用字符串资源?

Java 如何处理文本视图中的2链接单击使用字符串资源?,java,android,kotlin,Java,Android,Kotlin,我有一些带有两个链接的文本,如:“请阅读并接受我们的条款和隐私政策…” 。。。而且。。。 可能处理2个链接使用这种情况,当一个句子中有2个链接或需要使用另一种方法时 另外,我需要捕获单独的2次单击来发布事件以进行分析。我在我的应用程序中使用了以下内容 string.xml <string name="about_fragment_privacy_policy" translatable="false">User Agreement and P

我有一些带有两个链接的文本,如:“请阅读并接受我们的条款隐私政策…”

。。。而且。。。
可能处理2个链接使用这种情况,当一个句子中有2个链接或需要使用另一种方法时


另外,我需要捕获单独的2次单击来发布事件以进行分析。

我在我的应用程序中使用了以下内容

string.xml

<string name="about_fragment_privacy_policy" translatable="false">User Agreement and Privacy Policy</string>

看看这是否对你有帮助:不,我已经看到了这个链接。我认为这个链接会有帮助:Mahdi M-是的,似乎是,谢谢,谢谢大家!
<string name="about_fragment_privacy_policy" translatable="false">User Agreement and Privacy Policy</string>
<TextView
    android:id="@+id/privacyPolicy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/about_fragment_privacy_policy" />
string = getString(R.string.about_fragment_privacy_policy)
spannableString = SpannableString(string)
val clickableUserAgreement = object : ClickableSpan() {
    override fun onClick(widget: View) {
        startActivity(
            Intent(Intent.ACTION_VIEW).setData(
                Uri.parse(
                    "https://example.com"
                )
            )
        )
    }
}
val clickablePrivacyPolicy = object : ClickableSpan() {
    override fun onClick(widget: View) {
        startActivity(
            Intent(Intent.ACTION_VIEW).setData(
                Uri.parse(
                    "https://example.com"
                )
            )
        )
    }
}
spannableString.setSpan(
    clickableUserAgreement,
    0,
    14,
    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
    ForegroundColorSpan(resources.getColor(R.color.colorPrimary)),
    0,
    14,
    0
)
spannableString.setSpan(
    clickablePrivacyPolicy,
    19,
    string.length,
    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
    ForegroundColorSpan(resources.getColor(R.color.colorPrimary)),
    19,
    string.length,
    0
)
privacyPolicy.text = spannableString
privacyPolicy.movementMethod = LinkMovementMethod.getInstance()