2016-08-05 12 views
2

클릭 할 수있는 URL을 : 안드로이드 텍스트 뷰는 HTTP를 만들고 사용자 정의 방식은 내가 안드로이드 응용 프로그램을 만드는거야 다음과 같이 활동을 정의

<activity 
    android:name="com.scheme.app.MainActivity" 
    android:screenOrientation="portrait" 
    android:theme="@style/MainActivityTheme"> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <data 
      android:host="invite" 
      android:scheme="schemeapp" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
    </intent-filter> 
</activity> 

"schemeapp : // 초대"URL을 타격 할 때을 사용자는 MainActivity로 이동합니다.

textView.setText("Testing custom scheme - schemeapp://invite with http http://www.LMNGTFY.com"); 

내가 웹 URL (http://www.LMNGTFY.com)뿐만 아니라 사용자 정의 URL을 확인해야합니다 (schemeapp을 : // 초대) 클릭

나는 다음과 같은 내용으로 텍스트 뷰가 있습니다.

나는 이미 시도했다 : 나는 웹 URL을 감지하는 코드의 다음 줄을 제거하면

String text = "Testing custom scheme - schemeapp://invite with http http://www.LMNGTFY.com"; 
textView.setText(text); 
Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.ALL); 
Pattern urlDetect = Pattern.compile("(schemeapp):\\/\\/([a-zA-Z0-9.]+)"); 
Matcher matcher = urlDetect.matcher(text); 
String scheme = null; 

while (matcher.find()) { 
    String customSchemedUrl = matcher.group(0); 
    Uri uri = Uri.parse(customSchemedUrl); 
    scheme = uri.getScheme(); 
    break; 
} 

if (!TextUtils.isEmpty(scheme)) { 
    Linkify.addLinks(textView, urlDetect, scheme); 
} 

, 사용자 정의 방식의 URL이 작동합니다

Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.ALL); 

내가하려고하면 http를 사용자 정의 구성표 url로 추가하면 http url을 클릭 할 수 없습니다.

편집 : 명확한 설명

사용자 입력은 또한 텍스트 뷰에 표시하고 연결해야한다, 때문에 내가 HTML을 사용할 수 없습니다.

도와 주실 수 있습니까? 감사

답변

1

이것은 하나의 옵션 :

final Spanned html = Html.fromHtml("Testing custom scheme - <a href='schemeapp://invite'>schemeapp://invite</a> with http http://www.LMNGTFY.com";); 

helpText.setText(html); 
helpText.setMovementMethod(new LinkMovementMethod()); 
+0

덕분에, 즉 작동합니다,하지만 난의 텍스트 뷰는 사용자의 입력을 보여줍니다 HTML을 넣을 수 없습니다, 그래서 그들은 HTML 태그를 사용하지 않습니다. – manishKungwani

+0

콘텐츠가 크로스 플랫폼이기 때문에 userinput.replace ("schemapp : //.* ..", " ligi

+0

iPhone 응용 프로그램에서 동일하게 테스트하는 것)과 같은 텍스트를 사전 처리 할 수 ​​있습니다. – manishKungwani