skywang12345

导航

 

Android控件之TextView

1 TextView介绍

TextView是Android的文本显示器,主要用于文本显示。Android的TextView提供了许多属性和方法用于显示参数设置,参考下面表格:

2 TextView示例

建立一个activity,分别3个文本;
第一个文本,采用默认的字体大小和字体颜色置。
第二个文本,字体大小24sp,字体颜色绿色。
第三个文本,字体大小32sp,字体颜色#FF00BBCC。其中FF表示透明度为不透明,00BBCC是颜色值。

应用层代码

 1 package com.skywang.control;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 
 6 public class TextViewTest extends Activity {
 7     /** Called when the activity is first created. */
 8     @Override
 9     public void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.main);
12     }
13 }
View Code

manifest文件

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.skywang.control"
 4     android:versionCode="1"
 5     android:versionName="1.0" >
 6 
 7     <uses-sdk android:minSdkVersion="10" />
 8 
 9     <application
10         android:icon="@drawable/ic_launcher"
11         android:label="@string/app_name" >
12         <activity
13             android:name=".TextViewTest"
14             android:label="@string/app_name" >
15             <intent-filter>
16                 <action android:name="android.intent.action.MAIN" />
17 
18                 <category android:name="android.intent.category.LAUNCHER" />
19             </intent-filter>
20         </activity>
21     </application>
22 
23 </manifest>
View Code

layout文件

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent"
 5     android:orientation="vertical" >
 6 
 7     <TextView
 8         android:layout_width="fill_parent"
 9         android:layout_height="wrap_content"
10         android:text="@string/text_01" />
11 
12     <TextView
13         android:layout_width="fill_parent"
14         android:layout_height="wrap_content"
15         android:textColor="#00FF00"
16         android:textSize="24sp"
17         android:text="@string/text_02" />
18     
19     
20     <TextView
21         android:layout_width="fill_parent"
22         android:layout_height="wrap_content"
23         android:textColor="#FF00BBCC"
24         android:textSize="32sp"
25         android:text="@string/text_02" />
26     
27 </LinearLayout>
View Code

 

运行效果:如图

 


点击下载:源代码

 

posted on 2013-06-14 09:43  如果天空不死  阅读(1542)  评论(0编辑  收藏  举报