久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Android 上 TextView 中的多個可點擊鏈接

Multiple Clickable links in TextView on Android(Android 上 TextView 中的多個可點擊鏈接)
本文介紹了Android 上 TextView 中的多個可點擊鏈接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在類似于 Google & 的文本視圖中添加多個鏈接.Flipboard 的條款和條件隱私政策如下面的屏幕截圖所示:

I'm trying to add multiple links in a textview similar to what Google & Flipboard has done below with their Terms and conditions AND Privacy Policy shown in the screen shot below:

到目前為止,我偶然發現了這種方法

So far I've stumbled on using this approach

textView.setText(Html.fromHtml(myHtml);textView.setMovementMethod(LinkMovementMethod.getInstance());

textView.setText(Html.fromHtml(myHtml); textView.setMovementMethod(LinkMovementMethod.getInstance());

myHtml 是一個 href.

where myHtml is a href.

但它并沒有給我我需要的控制權,例如啟動片段等.

But it doesn't give me control I need e.g to launch a fragment etc.

知道他們是如何在下面的兩個示例中實現這一點的嗎?

Any idea how they achieve this in the two examples below?

推薦答案

你可以使用Linkify (android.text.Spannable,java.util.regex.Pattern,java.lang.String)

String termsAndConditions = getResources().getString(R.string.terms_and_conditions);
String privacyPolicy = getResources().getString(R.string.privacy_policy);

legalDescription.setText(
    String.format(
        getResources().getString(R.string.message),
        termsAndConditions,
        privacyPolicy)
);
legalDescription.setMovementMethod(LinkMovementMethod.getInstance());

Pattern termsAndConditionsMatcher = Pattern.compile(termsAndConditions);
Linkify.addLinks(legalDescription, termsAndConditionsMatcher, "terms:");

Pattern privacyPolicyMatcher = Pattern.compile(privacyPolicy);
Linkify.addLinks(legalDescription, privacyPolicyMatcher, "privacy:");

然后您可以使用該方案來啟動一個活動,例如通過在 AndroidManifest 中添加該方案:

and then you can use the scheme to start an activity for example by adding the scheme in the AndroidManifest:

<intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="terms" />
    <data android:scheme="privacy" />
</intent-filter>

如果您想執行自定義操作,可以將 Intent-filter 設置為您當前的活動,這將有一個 singleTop 啟動模式.

If you want to do a custom action, you can set the intent-filter to your current activity, which will have a singleTop launchmode.

這將導致 onNewIntent 在哪里被觸發可以進行自定義操作:

This will cause onNewIntent to be fired where can make your custom actions:

@Override
protected void onNewIntent(final Intent intent) {
 ...
  if (intent.getScheme().equals(..)) {
    ..
  }
}

這篇關于Android 上 TextView 中的多個可點擊鏈接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲精品国产成人 | 亚洲午夜精品一区二区三区他趣 | 亚洲高清一区二区三区 | 日韩久久精品视频 | 日韩一区二区三区视频 | 亚州精品天堂中文字幕 | 四季久久免费一区二区三区四区 | 久久国产精品免费视频 | 亚洲久草 | 久久久www成人免费无遮挡大片 | 欧美精品在线一区 | 亚洲一页 | 亚洲精品欧美精品 | 国产精品久久久久久久久图文区 | 一级黄色毛片免费 | 色婷婷久久久久swag精品 | 成人欧美一区二区三区白人 | 91爱爱·com | 亚洲三区在线观看 | 亚洲精品久久久久久久久久久久久 | 久久久久国产精品一区三寸 | 国产精品免费观看 | 一区二区三区视频免费看 | 久久99精品久久久久久 | 韩日三级 | 久久精品国产久精国产 | 男人阁久久| 97狠狠干 | 午夜影院在线观看版 | 国产视频一区二区三区四区五区 | 国产精品久久久久久久久免费桃花 | 国产一二区视频 | 91精品中文字幕一区二区三区 | 台湾佬成人网 | 久久不卡| 一区二区播放 | 91视频一区二区三区 | 欧美色综合一区二区三区 | 亚洲成人久久久 | 亚洲影音 | 手机日韩|