2017-02-11 80 views
0

所以我有一個textView,有時我的textView包含鏈接,目前當我點擊這個鏈接時,打開一個下載的瀏覽器列表的意圖打開。現在我想要的是,我想打開當前應用程序內的這個鏈接,在WebView中說。我怎樣才能做到這一點?處理android TextView的鏈接點擊

我們有同一主題的多篇文章/問題,但我不知道這篇文章/問題是真的。

這樣一個https://gist.github.com/ksoichiro/3394338給了我一個ClassCastException異常 android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan

或這一個handle textview link click in my android app

是有任何直接簡單的方法來實現這一目標?請告訴我。

+1

引用此回答 [在WebView中打開URL默認瀏覽器](http://stackoverflow.com/questions/22962621/open-url-in-webview-instead-of-default-browser) – sajan

回答

0

您可以使用Chrome自定義選項卡,這比加載網頁時的web視圖更快,並且定製非常簡單。

首先包括圖書館:

dependencies { 
    ... 
    compile 'com.android.support:customtabs:25.1.1' 
} 

然後在你的Activity當你調用的方法打開一個瀏覽器插件的java的這些行:

String url = ¨https://google.com/¨; 
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); 
CustomTabsIntent intent = builder.build(); 
intent.launchUrl(this, Uri.parse(url)); 

參考它的文檔在更多的自定義:
https://developer.chrome.com/multidevice/android/customtabs

相關問題