Android开发之UI组件TextView
2011-12-13 18:50
435 查看
UI组件TextView
属性:android:autoLink
我们用一个实例来解释这个属性
首先在strings.xml里写出我们需要的字符串
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TextViewTest</string>
<string name="webUrl">百度:http://baidu.com</string>
<string name="email">我的:296463139@qq.com</string>
<string name="phoneNumber">电话号码:10086</string>
<string name="autoSAll">百度:http://baidu.com 我的:296463139@qq.com</string>
</resources>
然后在我们的main.xml里声明属性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/webUrl" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="@string/email" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="@string/phoneNumber" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/autoSAll" />
<TextView
android:id="@+id/tvId"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/////////////Activity////////////////////
package cn.class3g.activity;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;
public class TextViewTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) this.findViewById(R.id.tvId);
String htmlStr = "<font size='30' color='#00FF22'>我</font>爱<b>你</b>"
+ "<a href='baidu.com'>百度</a>";
tv.setText(Html.fromHtml(htmlStr));
}
}
注意:
android:autoLink=”email” :会出现unsupported action,可能是模拟器bug,须探究
另外使用Html.fromHtml时,超链接只具备外观,不能跳转
效果图:
属性:android:autoLink
我们用一个实例来解释这个属性
首先在strings.xml里写出我们需要的字符串
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TextViewTest</string>
<string name="webUrl">百度:http://baidu.com</string>
<string name="email">我的:296463139@qq.com</string>
<string name="phoneNumber">电话号码:10086</string>
<string name="autoSAll">百度:http://baidu.com 我的:296463139@qq.com</string>
</resources>
然后在我们的main.xml里声明属性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/webUrl" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="@string/email" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="@string/phoneNumber" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/autoSAll" />
<TextView
android:id="@+id/tvId"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/////////////Activity////////////////////
package cn.class3g.activity;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;
public class TextViewTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) this.findViewById(R.id.tvId);
String htmlStr = "<font size='30' color='#00FF22'>我</font>爱<b>你</b>"
+ "<a href='baidu.com'>百度</a>";
tv.setText(Html.fromHtml(htmlStr));
}
}
注意:
android:autoLink=”email” :会出现unsupported action,可能是模拟器bug,须探究
另外使用Html.fromHtml时,超链接只具备外观,不能跳转
效果图:
![](http://hi.csdn.net/attachment/201112/13/0_13237735849y7b.gif)
相关文章推荐
- Android开发8:UI组件TextView,EditText,Button
- Android开发10.2:UI组件AutoCompleteTextView(自动完成文本框)
- Android应用开发之UI组件(TextView;EditText)
- Android开发10.2:UI组件AutoCompleteTextView(自动完成文本框)
- 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
- Android入门笔记 - 界面开发 - TextView,Button,EditText,Toast
- 【Android 开发】:TextView的几种使用方法
- Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全
- android开发,如何在用TextView中显示变量n的值
- Android用户界面开发之:TextView的使用实例
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- 50个Android开发技巧(10 为TextView添加样式)
- android-UI组件(二):TextView及其子类
- Android开发之TextView中间设置横线,适用于电商项目,商品原价之类的功能。
- [置顶] Android开发之TextView中间设置横线,适用于电商项目,商品原价之类的功能。
- android入门(一)---UI组件之文本框(TextView)
- Android控件开发之TextView
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- android开发中 如何动态更新TextView的内容?
- Android 开发 AutoCompleteTextView结合自定义的适配器,查询数据库