[Link.java]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.link);
TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"<a href=\"http://www.google.com\">link</a> " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
SpannableString ss = new SpannableString(
"text4: Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t4 = (TextView) findViewById(R.id.text4);
t4.setText(ss);
t4.setMovementMethod(LinkMovementMethod.getInstance());
}
[link.xml]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Four TextView widgets, each one displaying text containing links. -->
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="all"
android:text="@string/link_text_auto"
/>
<!-- text2 uses a string resource containing explicit <a> tags to
specify links. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/link_text_manual"
/>
<!-- text3 builds the text in the Java code using HTML. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<!-- text4 builds the text in the Java code without using HTML. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
[strings.xml]
this text are some things that are actionable. For instance,
you can click on http://www.google.com and it will launch the
web browser. You can click on google.com too. And, if you
click on (415) 555-1212 it should dial the phone.
</string>
<string name="link_text_manual"><b>text2:</b> This is some other
text, with a <a href="http://www.google.com">link</a> specified
via an <a> tag. Use a \"tel:\" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
'old > API_Demo' 카테고리의 다른 글
Views_Animation_3DTransition (0) | 2010.03.26 |
---|---|
Text_LogTextBox (0) | 2010.03.25 |
Content_Resources_Resources (0) | 2010.03.25 |
Content_Assets_ReadAsset (0) | 2010.03.25 |
APP_VoiceRecognition (0) | 2010.03.25 |