2012년 8월 14일 화요일

TextView에서 A tag(HTML)로 Activity 실행


TextView test = new TextView(getApplicationContext());

test .setText(Html.fromHtml("this is a <a href='http://www.google.com/'>test</a>"));
test .setMovementMethod(LinkMovementMethod.getInstance());

위과 같이 코드를 작성하면 test 글자에 링크가 걸리고, 누르면 웹 브라우져를 띄운다.

AndroidManifest.xml에서 다음과 같이 선언하고

<activity android:name="com.test.link.TestActivity">
    <intent-filter >
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="test"/>
    </intent-filter>
</activity>


test .setText(Html.fromHtml("this is a <a href='test://test01/'>test</a>"));

로 코드를 수정하면

TestActivity가 수행되고, intent의 uri로 "test://test01/" 문자열이 날아간다.



댓글 없음: