標籤:
---恢複內容開始---
1.建立Android工程
2.TextView文字顏色設定
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/mytext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffff00"
android:text="@string/hello"
/>
</LinearLayout>
運行效果如下
3.TextView文字大小設定
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/mytext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffff00"
android:textSize="22px"
android:text="@string/hello"
/>
</LinearLayout>
運行效果如下
4.TextView上下距離設定
<TextView
android:id="@+id/mytext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="30px"
android:text="網址:www.baidu.com"/>
運行效果如下
5.TextView距離上邊距離
<TextView
android:id="@+id/mytext3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:maxLength="3">(最多顯示3個文字)
android:text="ABABABABABABABA"/>
運行效果如下
6.TextView背景上的文字顯示
<TextView
android:id="@+id/mytext4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/log"(背景圖片)
android:textStyle="bold"(文字加粗)
android:text="這是背景圖片上的文字"/>
運行效果如下
7.TextView網址連結
<TextView
android:id="@+id/mytext5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="36px"
android:autoLink="all"
android:text="網址:www.baidu.com"/>
運行效果如下
8.使用樣式表定義常用的組件屬性方便維護
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="style_msg">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">36px</item>
<item name="android:autoLink">all</item>
</style>
</resources>
注意:此檔案放在values目錄下
main.xml使用如下
<TextView
android:id="@+id/mytext5"
style="@style/style_msg"
android:text="網址:www.baidu.com"/>
運行效果如下
Android-TextView(文本顯示組件2)