今天上午看了如何Google的一个示例代码,学到了一些和TextView相关的知识。消灭了我无知的认为TextView就是显示字的幼稚想法,我对学到了内容简单罗列一下就开始记录:
- 在strings.xml资源文件里面,设置斜体,加粗
- 给strings.xml里的字符串自动添加超链接
- 给strings.xml里的资源文件显式地添加超链接—通过< a >标记
- 在Java代码用HTML给文字添加超链接
- 在Java代码不用HTML给文字添加超链接
说一下,超链接不只是访问网页,也可以是一个电话号码。
先上图:
下面开始代码分析
首先先贴一下sample_main.xml的布局文件吧:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/intro" />
<!-- text_auto_linkify automatically linkifies things like URLs and phone numbers. -->
<TextView
android:id="@+id/text_auto_linkify"
style="@style/LinkText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/link_text_auto" />
<!--
text_html_resource uses a string resource containing explicit anchor tags (<a>)
to specify links.
-->
<TextView
android:id=&